Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For strings only, allow a leading slash. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ Glob is implemented to have both a functional form and an object-oriented form.

glob"a/?/c"

Attempting to creat a GlobMatch object from a string with a leading `/` or the empty string is an error.

2. A string, which will be converted into a GlobMatch expression:

"a/?/c" # equivalent to 1, above
"a/?/c" # equivalent to 1, above, except that a leading `/` is allowed here

3. A vector of strings and/or objects which implement `ismatch`, including `Regex` and `Glob.FilenameMatch` objects

Expand All @@ -32,8 +34,6 @@ Glob is implemented to have both a functional form and an object-oriented form.

4. A trailing `/` (or equivalently, a trailing empty string in the vector) will cause glob to only match directories

5. Attempting to creat a GlobMatch object from a string with a leading `/` or the empty string is an error

* `readdir(pattern::GlobMatch, [directory::String])` ::
* alias for `glob()`

Expand Down
4 changes: 4 additions & 0 deletions src/Glob.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ function glob(pattern, prefix::String="")
return matches
end

function glob(pattern::String)
first(pattern) == '/' ? glob(pattern[2:end], "/") : glob(pattern, "")
end

function _glob!(matches, pat::String)
i = 1
last = length(matches)
Expand Down