Skip to content

Commit

Permalink
Add a function
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Nov 26, 2024
1 parent 6f9cf4e commit b789a1a
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/utils/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub fn parse(pattern: &str) -> Vec<GlobElem> {

while remaining.len() > 0 {
if eat_asterisk_or_question(&mut remaining, &mut ans)
|| eat_escaped_char(&mut remaining, &mut ans) /*{
|| eat_string(&mut remaining, &mut ans)*/ {
|| eat_escaped_char(&mut remaining, &mut ans)
|| eat_string(&mut remaining, &mut ans) {
continue;
}

Expand Down Expand Up @@ -49,6 +49,23 @@ fn eat_escaped_char(pattern: &mut String, ans: &mut Vec<GlobElem>) -> bool {
true
}

fn eat_string(pattern: &mut String, ans: &mut Vec<GlobElem>) -> bool {
let mut len = 0;
for c in pattern.chars() {
if "@!+*?[\\".find(c) != None {
break;
}
len += c.len_utf8();
}

if len == 0 {
return false;
}

ans.push( GlobElem::Normal( consume(pattern, len) ));
true
}

fn consume(remaining: &mut String, cutpos: usize) -> String {
let cut = remaining[0..cutpos].to_string();
*remaining = remaining.split_off(cutpos);
Expand Down

0 comments on commit b789a1a

Please sign in to comment.