haltcase / glob

Pure Nim library for matching file paths against Unix style glob patterns.
https://glob.bolingen.me
MIT License
61 stars 5 forks source link

[WIP] simpler fix for handling case insensitivity #20

Closed timotheecour closed 6 years ago

timotheecour commented 6 years ago

tried on OSX (which is case insensitive), and passing a pattern with wrong case; it seems to work; am I missing something ?

WIP fix for https://github.com/citycide/glob/issues/12 , but a full PR would need to forward caseSensitive optional argument from top-level API, but something like that seems much simpler than https://github.com/citycide/glob/commit/7115d8d39d420beaf4bf4c3f167105183576c305

feel free to close this and incorporate that into your other PR

haltcase commented 6 years ago

Have you tested? Because this is where I started but this only works for matching a single path to a single pattern (ie using matches). It doesn't work in the walker, and it doesn't handle non-magic matches. The latter is why the makeCaseInsensitive proc exists in #19.

That proc takes a pattern like src/glob.nim and (on case sensitive systems where it's necessary) changes each character into a character class containing its lower and upper case forms (allowing it to match either in that position). That pattern ends up becoming [sS][rR][cC]/[gG][lL][oO][bB].[nN][iI][mM]. Now we can pass that to Nim's walkPattern iterator to find all the items that match.

So while in master we just check if the file exists - that doesn't work on case sensitive systems if you want a case insensitive match. We need to do the above to find all the possible matches. That make sense?

timotheecour commented 6 years ago

you may be right, will close for now