Skip to content

Commit

Permalink
fix a number formatting bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jan 15, 2025
1 parent 34bff83 commit 88397b0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,15 +951,18 @@ impl Formatter<'_> {
}
}
});
if formatted.starts_with(|c: char| c.is_ascii_digit())
&& (self
.output
.ends_with(|c: char| c.is_ascii_digit() || c == '¯')
|| self.output.ends_with('.')
&& (self.output.chars().nth_back(1))
.is_some_and(|c| c.is_ascii_digit()))
let curr = &mut self.output;
let new_starts_ascii = formatted.starts_with(|c: char| c.is_ascii_digit());
let new_starts_glyph = formatted.starts_with(['∞', 'η', 'π', 'τ']);
let curr_ends_neg = curr.ends_with('¯');
let curr_ends_ascii_or_neg =
curr_ends_neg || curr.ends_with(|c: char| c.is_ascii_digit());
let curr_ends_num_dup = curr.ends_with('.')
&& (curr.chars().nth_back(1)).is_some_and(|c| c.is_ascii_digit());
if new_starts_ascii && (curr_ends_ascii_or_neg || curr_ends_num_dup)
|| new_starts_glyph && curr_ends_neg
{
self.output.push(' ');
curr.push(' ');
}
self.push(&word.span, &formatted);
}
Expand Down

0 comments on commit 88397b0

Please sign in to comment.