pub fn from_lit_kind(src: &'a str, lit_kind: &LitKind) -> Option<NumericLiteral<'a>> {
if lit_kind.is_numeric() && src.chars().next().map_or(false, |c| c.is_digit(10)) {
- let (unsuffixed, suffix) = split_suffix(&src, lit_kind);
+ let (unsuffixed, suffix) = split_suffix(src, lit_kind);
let float = matches!(lit_kind, LitKind::Float(..));
Some(NumericLiteral::new(unsuffixed, suffix, float))
} else {
};
// Grab part of the literal after prefix, if present.
- let (prefix, mut sans_prefix) = if let Radix::Decimal = radix {
+ let (prefix, mut sans_prefix) = if radix == Radix::Decimal {
(None, lit)
} else {
let (p, s) = lit.split_at(2);
}
if let Some((separator, exponent)) = self.exponent {
- output.push_str(separator);
- Self::group_digits(&mut output, exponent, group_size, true, false);
+ if exponent != "0" {
+ output.push_str(separator);
+ Self::group_digits(&mut output, exponent, group_size, true, false);
+ }
}
if let Some(suffix) = self.suffix {
+ if output.ends_with('.') {
+ output.push('0');
+ }
output.push('_');
output.push_str(suffix);
}
let mut digits = input.chars().filter(|&c| c != '_');
+ // The exponent may have a sign, output it early, otherwise it will be
+ // treated as a digit
+ if digits.clone().next() == Some('-') {
+ let _ = digits.next();
+ output.push('-');
+ }
+
let first_group_size;
if partial_group_first {