Skip to content

Commit

Permalink
frame for character classes (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 13, 2022
1 parent 3afe2d2 commit 6b8d0d2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
45 changes: 43 additions & 2 deletions git-glob/src/wildmatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(crate) mod function {
const SLASH: u8 = b'/';
const BRACKET_OPEN: u8 = b'[';
const BRACKET_CLOSE: u8 = b']';
const COLON: u8 = b':';

const NEGATE_CLASS: u8 = b'!';

Expand Down Expand Up @@ -175,7 +176,7 @@ pub(crate) mod function {
loop {
match next {
None => return AbortAll,
Some((_p_idx, mut p_ch)) => match p_ch {
Some((p_idx, mut p_ch)) => match p_ch {
BACKSLASH => match p.next() {
Some((_, p_ch)) => {
if p_ch == t_ch {
Expand Down Expand Up @@ -211,7 +212,47 @@ pub(crate) mod function {
}
prev_p_ch = 0;
}
BRACKET_OPEN => todo!("class open"),
BRACKET_OPEN if matches!(p.peek(), Some((_, COLON))) => {
p.next();
while p.peek().map_or(false, |t| t.1 != BRACKET_CLOSE) {
p.next();
}
let closing_bracket_idx = match p.next() {
Some((idx, _)) => idx,
None => return AbortAll,
};
const BRACKET__COLON__BRACKET: usize = 3;
if closing_bracket_idx - p_idx < BRACKET__COLON__BRACKET
|| pattern[closing_bracket_idx - 1] != COLON
{
if t_ch == BRACKET_OPEN {
matched = true
}
p = pattern[p_idx + 1..]
.iter()
.map(possibly_lowercase)
.enumerate()
.peekable();
} else {
let class = &pattern.as_ref()[p_idx + 2..closing_bracket_idx - 1];
match class {
b"alnum" => todo!("alnum"),
b"alpha" => todo!("alpha"),
b"blank" => todo!("blank"),
b"cntrl" => todo!("cntrl"),
b"digit" => todo!("digit"),
b"graph" => todo!("graph"),
b"lower" => todo!("lower"),
b"print" => todo!("print"),
b"punct" => todo!("punct"),
b"space" => todo!("space"),
b"upper" => todo!("upper"),
b"xdigit" => todo!("xdigit"),
_ => return AbortAll,
};
prev_p_ch = 0;
}
}
_ => {
prev_p_ch = p_ch;
if p_ch == t_ch {
Expand Down
1 change: 0 additions & 1 deletion git-glob/tests/matching/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ impl<'a> Baseline<'a> {
}

#[test]
#[ignore]
fn compare_baseline_with_ours() {
let dir = git_testtools::scripted_fixture_repo_read_only("make_baseline.sh").unwrap();
let (mut total_matches, mut total_correct, mut panics) = (0, 0, 0);
Expand Down

0 comments on commit 6b8d0d2

Please sign in to comment.