Skip to content

Commit 88397b0

Browse files
committed
fix a number formatting bug
1 parent 34bff83 commit 88397b0

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/format.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -951,15 +951,18 @@ impl Formatter<'_> {
951951
}
952952
}
953953
});
954-
if formatted.starts_with(|c: char| c.is_ascii_digit())
955-
&& (self
956-
.output
957-
.ends_with(|c: char| c.is_ascii_digit() || c == '¯')
958-
|| self.output.ends_with('.')
959-
&& (self.output.chars().nth_back(1))
960-
.is_some_and(|c| c.is_ascii_digit()))
954+
let curr = &mut self.output;
955+
let new_starts_ascii = formatted.starts_with(|c: char| c.is_ascii_digit());
956+
let new_starts_glyph = formatted.starts_with(['∞', 'η', 'π', 'τ']);
957+
let curr_ends_neg = curr.ends_with('¯');
958+
let curr_ends_ascii_or_neg =
959+
curr_ends_neg || curr.ends_with(|c: char| c.is_ascii_digit());
960+
let curr_ends_num_dup = curr.ends_with('.')
961+
&& (curr.chars().nth_back(1)).is_some_and(|c| c.is_ascii_digit());
962+
if new_starts_ascii && (curr_ends_ascii_or_neg || curr_ends_num_dup)
963+
|| new_starts_glyph && curr_ends_neg
961964
{
962-
self.output.push(' ');
965+
curr.push(' ');
963966
}
964967
self.push(&word.span, &formatted);
965968
}

0 commit comments

Comments
 (0)