Simple bracket expressions#1138
Simple bracket expressions#1138noahboa27 wants to merge 2 commits intotrifectatechfoundation:mainfrom
Conversation
I decided to go with the existing loop style as the `wildcard_match` function for continuity, simplicity, and index control.
| let mut is_negated = false; | ||
| let mut last_dash = None; | ||
|
|
||
| while let Some(p) = pattern.get(pattern_index) { |
There was a problem hiding this comment.
Wouldn't it be better to use an iterator instead of using an explicit index? I see a lot of += 1 below.
|
|
||
| #[allow(dead_code)] | ||
| pub(super) fn bracket_match(test: &[u8], pattern: &[u8]) -> bool { | ||
| let mut match_cases: Vec<u8> = Vec::new(); |
There was a problem hiding this comment.
Using a Vec for a pattern wouldn't by my solution.
For range patterns like [a-z] it feels wasteful, but also a pattern like [ëä] should ideally be supported and Vec<u8> won't work very well there.
I don't think it's absolutely necessary in code like this to first build a full representation, and then check against the representation. I.e. first see if the first character is ! or ^, and then interpret it as a negated pattern. And then there are two cases: either it is a range or the pattern is simply "itself" (i.e. a slice of characters)
Maybe the wildcard_match function (and this one) should also take &str instead of &[u8].
|
Closing this PR because it is stale and the issue it tries to address (#1136) has been closed, for rationale I refer to #1136 (comment) Thanks for hacking on sudo-rs, though! |
I decided to go with the existing loop style as the
wildcard_matchfunction for continuity, simplicity, and index control. With this draft I have a few questions:[[[//**//]]]or invalid patterns such as[].[a-],[-a], or[\w]?Thank you for your time and comments 😁