pr: replace regex with hand-written argument parsers#11774
Open
sylvestre wants to merge 1 commit intouutils:mainfrom
Open
pr: replace regex with hand-written argument parsers#11774sylvestre wants to merge 1 commit intouutils:mainfrom
sylvestre wants to merge 1 commit intouutils:mainfrom
Conversation
|
GNU testsuite comparison: |
|
Binary size comparison: |
cakebaker
reviewed
Apr 13, 2026
| } | ||
|
|
||
| /// Extract the `digits[:digits]` part from a `+digits[:digits]` token found anywhere in the string. | ||
| fn extract_plus_page(s: &str) -> Option<String> { |
Contributor
There was a problem hiding this comment.
I think you can return an Option<&str>.
cakebaker
reviewed
Apr 13, 2026
|
|
||
| /// Extract the digits part from a `-digits` token found anywhere in the string. | ||
| /// Equivalent to the regex `\s*-(\d+)\s*` capture group 1. | ||
| fn extract_minus_col(s: &str) -> Option<String> { |
cakebaker
reviewed
Apr 13, 2026
Comment on lines
+461
to
+465
| let mut chars = s.chars(); | ||
| match chars.next() { | ||
| Some('-') | None => false, | ||
| Some(_) => chars.all(|c| c.is_ascii_digit()), | ||
| } |
Contributor
There was a problem hiding this comment.
I would use an early exit instead of a match:
Suggested change
| let mut chars = s.chars(); | |
| match chars.next() { | |
| Some('-') | None => false, | |
| Some(_) => chars.all(|c| c.is_ascii_digit()), | |
| } | |
| if s.is_empty() || s.starts_with('-') { | |
| return false; | |
| } | |
| s.chars().skip(1).all(|c| c.is_ascii_digit()) |
cakebaker
reviewed
Apr 13, 2026
|
|
||
| /// Check if string matches `^-n\s*$` (is `-n` optionally followed by whitespace). | ||
| fn is_n_flag(s: &str) -> bool { | ||
| s.trim().trim_end() == "-n" |
Contributor
There was a problem hiding this comment.
The trim() is not correct if you want to ensure the string starts with -n.
Suggested change
| s.trim().trim_end() == "-n" | |
| s.trim_end() == "-n" |
cakebaker
reviewed
Apr 13, 2026
|
|
||
| /// Check if string matches `^-e` (starts with `-e`). | ||
| fn is_e_flag(s: &str) -> bool { | ||
| s.trim().starts_with("-e") |
Contributor
There was a problem hiding this comment.
Same here.
Suggested change
| s.trim().starts_with("-e") | |
| s.starts_with("-e") |
cakebaker
reviewed
Apr 13, 2026
| /// Removes -column and +page option as getopts cannot parse things like -3 etc | ||
| /// # Arguments | ||
| /// * `args` - Command line arguments | ||
| /// Removes -column and +page option as getopts cannot parse things like -3 etc. |
Contributor
There was a problem hiding this comment.
I guess it should be clap as we don't use getopts.
Suggested change
| /// Removes -column and +page option as getopts cannot parse things like -3 etc. | |
| /// Removes -column and +page option as clap cannot parse things like -3 etc. |
cakebaker
reviewed
Apr 13, 2026
| None => 1, | ||
| }; | ||
|
|
||
| let end_page_in_plus_option = match page_plus_match { |
Contributor
There was a problem hiding this comment.
As the logic is similar to start_page_in_plus_option it might be possible to combine them.
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.
No description provided.