Skip to content

Commit f273f28

Browse files
committed
Improve parsing of base prefixes and suffixes.
1 parent 3c0003c commit f273f28

File tree

9 files changed

+205
-199
lines changed

9 files changed

+205
-199
lines changed

lexical-parse-float/src/parse.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,8 @@ pub fn parse_number<'a, const FORMAT: u128, const IS_PARTIAL: bool>(
503503
let bits_per_base = shared::log2(format.exponent_base()) as i64;
504504

505505
// skip and validate an optional base prefix
506-
let has_base_prefix = cfg!(feature = "format") && byte.read_base_prefix();
507-
if cfg!(feature = "format") && !has_base_prefix && format.required_base_prefix() {
508-
return Err(Error::MissingBasePrefix(byte.cursor()));
509-
}
506+
let has_base_prefix =
507+
cfg!(all(feature = "format", feature = "power-of-two")) && byte.read_base_prefix()?;
510508

511509
// INTEGER
512510

@@ -703,18 +701,7 @@ pub fn parse_number<'a, const FORMAT: u128, const IS_PARTIAL: bool>(
703701
}
704702

705703
// Check to see if we have a valid base suffix.
706-
// We've already trimmed any leading digit separators here, so we can be safe
707-
// that the first character **is not** a digit separator.
708-
if cfg!(all(feature = "format", feature = "power-of-two")) && format.has_base_suffix() {
709-
let base_suffix = format.base_suffix();
710-
let is_suffix = byte.first_is(base_suffix, format.case_sensitive_base_suffix());
711-
if is_suffix {
712-
// SAFETY: safe since `byte.len() >= 1`.
713-
unsafe { byte.step_unchecked() };
714-
} else if format.required_base_suffix() {
715-
return Err(Error::MissingBaseSuffix(byte.cursor()));
716-
}
717-
}
704+
_ = byte.read_base_suffix(has_exponent)?;
718705

719706
// CHECK OVERFLOW
720707

0 commit comments

Comments
 (0)