refactor(menu): remove the panic surfaces in parse_selection_char and truncate_with_ansi - #1165
Open
kronberger-droid wants to merge 3 commits into
Open
Conversation
Characterisation cases ahead of restructuring the truncation loop. The existing cases only used escapes with a trailing ';', which the parser reads as a reset, so none of them exercised style preservation across the cut.
…th ansi The find loop carried a bool and two indexes that only described the same cut through the budget arithmetic: the byte offset survived later segments because their walk hit a zero budget before assigning. A Fit enum names the three outcomes and a Cut struct is set in one place, thus the emit phase reads slices via split_at_checked instead of indexing. Also pulls the suffix into a const and the grapheme walk into a helper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two of the
menu_functions.rssites flagged byclippy::expect_used/clippy::indexing_slicing,part of a sweep to move the crate's panic surfaces toward zero.
Neither was a reachable panic in practice; both were invariants the code re-checked because the types did not carry them.
parse_selection_char:to_digit(10).expect(..)right afteris_ascii_digit().Fused into
if let Some(d) = c.to_digit(10)so the guard and the conversion are one operation.truncate_with_ansi: the find loop carried a bool and two indexes that only described the same cut through the budget arithmetic.A
Fitenum names the three ways a segment can sit against the width budget,a
Cutstruct is set in exactly one place,and the emit phase reads slices via
split_at_checkedandfirst()instead of indexing.Additional notes
The
...moved into aTRUNCATION_SUFFIXconst and the grapheme walk intoprefix_len_within_width.Middle commit adds eleven characterisation cases for
truncate_with_ansiahead of the rewrite.string_differencestill has four sites in this file; it wants its own pass and follows separately.