From 08f8983085aeca8348147bebdffc847f4ed2b9b1 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 25 May 2024 17:20:08 -0400 Subject: [PATCH] Adopt the new hex float parsing This eliminates hexponent. --- Cargo.lock | 6 ------ Cargo.toml | 1 - src/wutil/hex_float.rs | 1 - src/wutil/wcstod.rs | 26 ++++++++------------------ 4 files changed, 8 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fdaf4eb03..637ba6906 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,7 +102,6 @@ dependencies = [ "cc", "errno", "fast-float", - "hexponent", "lazy_static", "libc", "lru", @@ -151,11 +150,6 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -[[package]] -name = "hexponent" -version = "0.3.1" -source = "git+https://github.com/fish-shell/hexponent?branch=fish#71febaf2ffa3c63ea50a70aa4308293d69bd709c" - [[package]] name = "itertools" version = "0.9.0" diff --git a/Cargo.toml b/Cargo.toml index 1519b66e9..6f8263024 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ default-run = "fish" [dependencies] pcre2 = { git = "https://github.com/fish-shell/rust-pcre2", branch = "master", default-features = false, features = ["utf32"] } fast-float = { git = "https://github.com/fish-shell/fast-float-rust", branch="fish" } -hexponent = { git = "https://github.com/fish-shell/hexponent", branch="fish" } printf-compat = { git = "https://github.com/fish-shell/printf-compat.git", branch="fish" } bitflags = "2.4.0" diff --git a/src/wutil/hex_float.rs b/src/wutil/hex_float.rs index 96d28068d..f79cf0b92 100644 --- a/src/wutil/hex_float.rs +++ b/src/wutil/hex_float.rs @@ -45,7 +45,6 @@ /// A `Result` containing either: /// - A tuple of the parsed floating-point number (`f64`) and the number of characters consumed (`usize`), or /// - A `SyntaxError` if the parsing fails. -#[allow(dead_code)] pub fn parse_hex_float( chars: impl Iterator, decimal_sep: char, diff --git a/src/wutil/wcstod.rs b/src/wutil/wcstod.rs index 42f51e675..ca2322860 100644 --- a/src/wutil/wcstod.rs +++ b/src/wutil/wcstod.rs @@ -1,4 +1,5 @@ use super::errors::Error; +use super::hex_float; use crate::wchar::IntoCharIter; use fast_float::parse_partial_iter; @@ -22,14 +23,14 @@ fn wcstod_inner(mut chars: I, decimal_sep: char, consumed: &mut usize) -> Res } } - // If it's a hex float, use hexponent. + // If it's a hex float, parse it. if is_hex_float(chars.clone()) { - let mut n = 0; - let res = hexponent::parse_hex_float(chars, decimal_sep, &mut n); - if res.is_ok() { - *consumed = whitespace_skipped + n; - } - return res.map_err(hexponent_error); + return if let Ok((f, amt)) = hex_float::parse_hex_float(chars, decimal_sep) { + *consumed = whitespace_skipped + amt; + Ok(f) + } else { + Err(Error::InvalidChar) + }; } let ret = parse_partial_iter(chars.clone().fuse(), decimal_sep); @@ -100,17 +101,6 @@ pub fn is_hex_float>(mut chars: Chars) -> bool { } } -// Convert a a hexponent error to our error type. -fn hexponent_error(e: hexponent::ParseError) -> Error { - use hexponent::ParseErrorKind; - match e.kind { - ParseErrorKind::MissingPrefix - | ParseErrorKind::MissingDigits - | ParseErrorKind::MissingExponent => Error::InvalidChar, - ParseErrorKind::ExponentOverflow => Error::Overflow, - } -} - /// Like [`wcstod()`], but allows underscore separators. Leading, trailing, and multiple underscores /// are allowed, as are underscores next to decimal (`.`), exponent (`E`/`e`/`P`/`p`), and /// hexadecimal (`X`/`x`) delimiters. This consumes trailing underscores -- `consumed` will include