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

Glob object model support for ** #54

Closed
kunalkaroth opened this issue Aug 20, 2018 · 5 comments
Closed

Glob object model support for ** #54

kunalkaroth opened this issue Aug 20, 2018 · 5 comments
Labels

Comments

@kunalkaroth
Copy link

Your globbing library is pretty nice. I was wondering if there’s a way to glob a pattern like this using the GlobBuilder: [a-zA-Z0-9]**

I can do it with string parsing, Glob.Parse(); but I seek high performance and was wondering if it would be possible to use the GlobBuilder to achieve the same.
new GlobBuilder().LetterInRange('a', 'z').Wildcard().WildCard() -> [a-z]**

.Wildcard().WildCard() doesn't seem to be equivalent to "**".

Also, another thing that’s problematic is being able to do, [a-zA-Z0-9]**.

Finally, I want to glob files with a certain extension for e.g., *.pdb this doesn't seem to work at the moment?

@dazinator
Copy link
Owner

dazinator commented Aug 24, 2018

Thanks!
For .Wildcard().WildCard() I think you want .DirectoryWildcard()

For [a-zA-Z0-9]** are you saying you want to match one single character that is within the range a-z or A-Z or 0-9, followed by anything?

** can only be used when its the only thing in a segment.. i.e foo/**/bar is fine. foo** is not fine.

At the moment I think you could create three seperate globs like so:

[a-z]/**, [A-Z]/** and [0-9]/**

Using the glob builder that might be something like:

var lowerCase = new GlobBuilder().LetterInRange('a', 'z')
                                                     .PathSeperator(PathSeperatorKind.BackwardSlash)
                                                     .DirectoryWildcard()
                                                     .ToGlob();

var upperCase = new GlobBuilder().LetterInRange('A', 'Z')
                                                     .PathSeperator(PathSeperatorKind.BackwardSlash)
                                                     .DirectoryWildcard()
                                                     .ToGlob();

var number = new GlobBuilder().NumberInRange(0,9)
                                                     .PathSeperator(PathSeperatorKind.BackwardSlash)
                                                     .DirectoryWildcard()
                                                     .ToGlob();

Actually you can condense that to two seperate globs, by doing a case-insenstive match for the a-z. For example:


var options = new GlobOptions();
options.Evaluation.CaseInsensitive = true;

var letterGlob = new GlobBuilder().LetterInRange('a', 'z')
                                                .PathSeperator(PathSeperatorKind.BackwardSlash)
                                                .DirectoryWildcard()
                                                .ToGlob(options);

var numberGlob = new GlobBuilder().NumberInRange(0,9)
                                                     .PathSeperator(PathSeperatorKind.BackwardSlash)
                                                     .DirectoryWildcard();

var result = letterGlob.IsMatch("a/foo/bar/baz") || numberGlob.IsMatch("a/foo/bar/baz");

However I am not sure I can do better than this seperate glob idea at present - i.e I don't think you can create a single glob, that matchesa single character that is within the range a-zA-Z0-9 at present.

Hopefully that makes sense to you.

@dazinator
Copy link
Owner

To glob files with a certain extension?

*.pdb should work for example.

if you want any directory: /**/*.pdb

You can have a look at the test cases as they might help aid you.

@DoCode
Copy link

DoCode commented Aug 29, 2018

How to select multiple wildcards:
**/package.id/**/*.pdb

@dazinator
Copy link
Owner

Closing this for now, hopefully your question is answered but let me know if not.

@kunalkaroth
Copy link
Author

@dazinator : Thanks for the detailed responses. I wasn't aware of the .DirectoryWildcard() for some reason. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants