Skip to content

Commit

Permalink
Add support for ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
oalders committed Jul 10, 2024
1 parent 9c2404f commit 27bd15d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions zglob.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ func New(pattern string) (*zenv, error) {
} else {
filemask += "[^/]*"
}
} else if cc[i] == '[' { // range
staticDir = false
pattern := ""
for j := i + 1; j < len(cc); j++ {
if cc[j] == ']' {
i = j
break
} else {
pattern += string(cc[j])
}
}
if pattern != "" {
filemask += "[" + pattern + "]"
continue
}
} else {
if cc[i] == '{' {
staticDir = false
Expand Down
4 changes: 4 additions & 0 deletions zglob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var testGlobs = []testZGlob{
{`fo*`, []string{`foo`}, nil},
{`foo`, []string{`foo`}, nil},
{`foo/*`, []string{`foo/bar`, `foo/baz`}, nil},
{`foo/b[a]*`, []string{`foo/bar`, `foo/baz`}, nil},
{`foo/b[a][r]*`, []string{`foo/bar`}, nil},
{`foo/b[a-z]*`, []string{`foo/bar`, `foo/baz`}, nil},
{`foo/b[c-z]*`, []string{}, nil},
{`foo/**`, []string{`foo/bar`, `foo/baz`}, nil},
{`f*o/**`, []string{`foo/bar`, `foo/baz`}, nil},
{`*oo/**`, []string{`foo/bar`, `foo/baz`, `hoo/bar`}, nil},
Expand Down

0 comments on commit 27bd15d

Please sign in to comment.