Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Nov 16, 2024
1 parent 62bdf99 commit 75e00f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
9 changes: 6 additions & 3 deletions vlib/builtin/string.v
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,9 @@ pub fn (name string) match_glob(pattern string) bool {
nlen := name.len
for px < plen || nx < nlen {
if px < plen {
if nx == nlen {
break
}
c := pattern[px]
match c {
`?` {
Expand All @@ -2674,8 +2677,8 @@ pub fn (name string) match_glob(pattern string) bool {
// Try to match at nx.
// If that doesn't work out, restart at nx+1 next.
next_px = px
next_nx = nx + 1
px++
next_nx = nx
nx++
continue
}
`[` {
Expand Down Expand Up @@ -2731,7 +2734,7 @@ pub fn (name string) match_glob(pattern string) bool {
if 0 < next_nx && next_nx <= nlen {
// A mismatch, try restarting:
px = next_px
nx = next_nx
nx = next_nx + 1
continue
}
return false
Expand Down
20 changes: 20 additions & 0 deletions vlib/strings/match_glob_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
fn test_main() {
assert '1*b'.match_glob('*[*]b') == true
assert '1*b'.match_glob('1[*]b') == true

assert '1****b'.match_glob('1*b') == true
assert '1****b'.match_glob('1[*]b') == false
assert '1****b'.match_glob('*[*]b') == true
assert '*b'.match_glob('*[*]b') == true

assert '**'.match_glob('*[*]') == true
assert '**'.match_glob('[*]*') == true

assert '**'.match_glob('*?') == true
assert '**'.match_glob('?*') == true

assert '**'.match_glob('[*]?') == true
assert '**'.match_glob('?[*]') == true

assert '**'.match_glob('??') == true
}

0 comments on commit 75e00f4

Please sign in to comment.