diff --git a/fish-rust/src/wutil/wcstod.rs b/fish-rust/src/wutil/wcstod.rs index 48fc663d7..73c136849 100644 --- a/fish-rust/src/wutil/wcstod.rs +++ b/fish-rust/src/wutil/wcstod.rs @@ -2,28 +2,11 @@ use super::errors::Error; use crate::wchar::IntoCharIter; use fast_float::parse_partial_iter; -/// Parses a 64-bit floating point number. -/// -/// Leading whitespace and trailing characters are ignored. If the input -/// string does not contain a valid floating point number (where e.g. -/// `"."` is seen as a valid floating point number), `None` is returned. -/// Otherwise the parsed floating point number is returned. -/// -/// The `decimal_sep` parameter is used to specify the decimal separator. -/// '.' is a normal default. -/// -/// The `consumed` parameter is used to return the number of characters -/// consumed, similar to the "end" parameter to strtod. -/// This is only meaningful if parsing succeeds. -/// -/// Error::Overflow is returned if the value is too large in magnitude. -pub fn wcstod(input: Chars, decimal_sep: char, consumed: &mut usize) -> Result +fn wcstod_inner(mut chars: I, decimal_sep: char, consumed: &mut usize) -> Result where - Chars: IntoCharIter, + I: Iterator + Clone, { - let mut chars = input.chars(); let mut whitespace_skipped = 0; - // Skip leading whitespace. loop { match chars.clone().next() { @@ -73,6 +56,28 @@ where Ok(val) } +/// Parses a 64-bit floating point number. +/// +/// Leading whitespace and trailing characters are ignored. If the input +/// string does not contain a valid floating point number (where e.g. +/// `"."` is seen as a valid floating point number), `None` is returned. +/// Otherwise the parsed floating point number is returned. +/// +/// The `decimal_sep` parameter is used to specify the decimal separator. +/// '.' is a normal default. +/// +/// The `consumed` parameter is used to return the number of characters +/// consumed, similar to the "end" parameter to strtod. +/// This is only meaningful if parsing succeeds. +/// +/// Error::Overflow is returned if the value is too large in magnitude. +pub fn wcstod(input: Chars, decimal_sep: char, consumed: &mut usize) -> Result +where + Chars: IntoCharIter, +{ + wcstod_inner(input.chars(), decimal_sep, consumed) +} + /// Check if a character iterator appears to be a hex float. /// That is, an optional + or -, followed by 0x or 0X, and a hex digit. pub fn is_hex_float>(mut chars: Chars) -> bool {