History

frame for character classes (#301)

Sebastian Thiel committed 4 years ago

Commit 6b8d0d21 parent 3afe2d22 files · +43 −3Browse files

Unified · Split

2 files
  1. git-glob/src/wildmatch.rs +43 −2
  2. git-glob/tests/matching/mod.rs +0 −1
git-glob/src/wildmatch.rs+43−2
@@ -27,6 +27,7 @@ pub(crate) mod function { · 26 unmodified lines
2727 const SLASH: u8 = b'/';
2828 const BRACKET_OPEN: u8 = b'[';
2929 const BRACKET_CLOSE: u8 = b']';
30+ const COLON: u8 = b':';
3031
3132 const NEGATE_CLASS: u8 = b'!';
3233
@@ -175,7 +176,7 @@ pub(crate) mod function { · 142 unmodified lines
175176 loop {
176177 match next {
177178 None => return AbortAll,
178− Some((_p_idx, mut p_ch)) => match p_ch {
179+ Some((p_idx, mut p_ch)) => match p_ch {
179180 BACKSLASH => match p.next() {
180181 Some((_, p_ch)) => {
181182 if p_ch == t_ch {
@@ -211,7 +212,47 @@ pub(crate) mod function { · 29 unmodified lines
211212 }
212213 prev_p_ch = 0;
213214 }
214− BRACKET_OPEN => todo!("class open"),
215+ BRACKET_OPEN if matches!(p.peek(), Some((_, COLON))) => {
216+ p.next();
217+ while p.peek().map_or(false, |t| t.1 != BRACKET_CLOSE) {
218+ p.next();
219+ }
220+ let closing_bracket_idx = match p.next() {
221+ Some((idx, _)) => idx,
222+ None => return AbortAll,
223+ };
224+ const BRACKET__COLON__BRACKET: usize = 3;
225+ if closing_bracket_idx - p_idx < BRACKET__COLON__BRACKET
226+ || pattern[closing_bracket_idx - 1] != COLON
227+ {
228+ if t_ch == BRACKET_OPEN {
229+ matched = true
230+ }
231+ p = pattern[p_idx + 1..]
232+ .iter()
233+ .map(possibly_lowercase)
234+ .enumerate()
235+ .peekable();
236+ } else {
237+ let class = &pattern.as_ref()[p_idx + 2..closing_bracket_idx - 1];
238+ match class {
239+ b"alnum" => todo!("alnum"),
240+ b"alpha" => todo!("alpha"),
241+ b"blank" => todo!("blank"),
242+ b"cntrl" => todo!("cntrl"),
243+ b"digit" => todo!("digit"),
244+ b"graph" => todo!("graph"),
245+ b"lower" => todo!("lower"),
246+ b"print" => todo!("print"),
247+ b"punct" => todo!("punct"),
248+ b"space" => todo!("space"),
249+ b"upper" => todo!("upper"),
250+ b"xdigit" => todo!("xdigit"),
251+ _ => return AbortAll,
252+ };
253+ prev_p_ch = 0;
254+ }
255+ }
215256 _ => {
216257 prev_p_ch = p_ch;
217258 if p_ch == t_ch {
git-glob/tests/matching/mod.rs+0−1
@@ -42,7 +42,6 @@ impl<'a> Baseline<'a> { · 41 unmodified lines
4242 }
4343
4444 #[test]
45−#[ignore]
4645 fn compare_baseline_with_ours() {
4746 let dir = git_testtools::scripted_fixture_repo_read_only("make_baseline.sh").unwrap();
4847 let (mut total_matches, mut total_correct, mut panics) = (0, 0, 0);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t