vFindRegex::vFindRegex(std::wstring patternInput, bool recursive) { if (recursive) state = new RvFindRegex(); else state = new NRvFindRegex(); if (globalOptions::expandRegex && std::find(patternInput.begin(), patternInput.end(), L'\\') != patternInput.end()) { DWORD len = GetLongPathName(patternInput.c_str(), NULL, NULL); wchar_t *tempExpandedPath = new wchar_t[len]; GetLongPathName(patternInput.c_str(), tempExpandedPath, len); patternInput = tempExpandedPath; delete [] tempExpandedPath; } std::wstring::const_iterator middle(std::find(patternInput.rbegin(), patternInput.rend(), L'\\').base()); if (middle == patternInput.begin()) { regex = patternInput; } else { regex = std::wstring(middle, patternInput.end()); pathRoot = std::wstring(patternInput.begin(), middle); } if (!fpattern_isvalid(regex.c_str())) throw L"There is an error in the syntax of your VFIND regular expression."; stripEscapes(pathRoot); }
int fpattern_matchn(const char *pat, const char *fname, int flength, int keepcase) { int rc; /* Check args */ if (fname == NULL) return (FALSE); if (pat == NULL) return (FALSE); /* Assume that pattern is well-formed * NOTA BENE: this function may crash on invalid patterns! */ assert(fpattern_isvalid(pat)); /* Attempt to match pattern against filename */ if (flength < 0) flength = (int)strlen(fname); if (keepcase) rc = fpattern_submatch(pat, fname, flength); else rc = fpattern_submatch_tolower(pat, fname, flength); return (rc); }
int fpattern_match(const char *pat, const char *fname, int flength, int keepcase) { int rc; /* Check args */ if (fname == NULL) return (FALSE); if (pat == NULL) return (FALSE); /* Verify that the pattern is valid, and get its length */ if (!fpattern_isvalid(pat)) return (FALSE); /* Attempt to match pattern against filename */ if (flength < 0) flength = (int)strlen(fname); if (flength == 0) return (pat[0] == '\0'); /* Special case */ if (keepcase) rc = fpattern_submatch(pat, fname, flength); else rc = fpattern_submatch_tolower(pat, fname, flength); return (rc); }
FileIterator::Status FileIterImpUnix::findFirst( const String &findStr, FileAttributes &attrs ) { FileIterator::Status status = FileIterator::cFindError; closeFind(); // split the filter from the base path StringUtils::splitBack( FileUtils::PATH_SEP, findStr, &_basePath, &_filter); // Make sure that the user has not passed us a directory FileAttributes sourceAttrs; if ( fpattern_isvalid(_filter.c_str()) && FileUtils::getAttributes(_basePath, sourceAttrs) && sourceAttrs.isDirectory() ) { // have the directory, so now start returning the // and a valid starch path - make sure that the // path is fully resolved char resolvedPath[MAXPATHLEN+1]; resolvedPath[0] = '\0'; if ( ::realpath(_basePath.c_str(), resolvedPath) != NULL ) { _fd = ::opendir( resolvedPath ); if ( _fd != NULL ) { status = findNext( attrs ); } } } return status; }
int fpattern_match(const char *pat, const char *fname) { int rc; /* Check args */ if (fname == NULL) return (FALSE); if (pat == NULL) return (FALSE); /* Verify that the pattern is valid, and get its length */ if (!fpattern_isvalid(pat)) return (FALSE); /* Attempt to match pattern against filename */ if (fname[0] == '\0') return (pat[0] == '\0'); /* Special case */ rc = fpattern_submatch(pat, fname); return (rc); }
int main(int argc, char **argv) { (void) argc; /* Shut up lint */ (void) argv; /* Shut up lint */ #if DEBUG dbg_f = stdout; #endif printf("==========================================\n"); setlocale(LC_CTYPE, ""); #if 1 /* Set to nonzero to stop on first failure */ stop_on_fail = TRUE; #endif test(0, NULL, NULL); test(0, NULL, ""); test(0, NULL, "abc"); test(0, "", NULL); test(0, "abc", NULL); test(1, "abc", "abc"); test(0, "ab", "abc"); test(0, "abcd", "abc"); test(0, "Foo.txt", "Foo.x"); test(1, "Foo.txt", "Foo.txt"); test(1, "Foo.txt", "foo.txt"); test(1, "FOO.txt", "foo.TXT"); test(1, "a", "?"); test(1, "foo.txt", "f??.txt"); test(1, "foo.txt", "???????"); test(0, "foo.txt", "??????"); test(0, "foo.txt", "????????"); test(1, "*", "`*"); test(1, "A[", "a`["); test(1, "a`x", "a``x"); test(1, "*`?", "`*```?"); test(1, "a*x", "a`*x"); test(1, "a€", "a`80"); test(0, "a€", "a`8"); #if defined FPAT_DELIM test(0, "", "/"); test(0, "", "\\"); test(1, "/", "/"); test(1, "/", "\\"); test(1, "\\", "/"); test(1, "\\", "\\"); test(1, "a/b", "a/b"); test(1, "a/b", "a\\b"); test(1, "/", "*/*"); test(1, "foo/a.c", "f*/*.?"); test(1, "foo/a.c", "*/*"); test(0, "foo/a.c", "/*/*"); test(0, "foo/a.c", "*/*/"); test(1, "/", "~/~"); test(1, "foo/a.c", "f~/~.?"); test(0, "foo/a.c", "~/~"); test(1, "foo/abc", "~/~"); test(0, "foo/a.c", "/~/~"); test(0, "foo/a.c", "~/~/"); #endif test(0, "", "*"); test(1, "a", "*"); test(1, "ab", "*"); test(1, "abc", "**"); test(1, "ab.c", "*.?"); test(1, "ab.c", "*.*"); test(1, "ab.c", "*?"); test(1, "ab.c", "?*"); test(1, "ab.c", "?*?"); test(1, "ab.c", "?*?*"); test(1, "ac", "a*c"); test(1, "axc", "a*c"); test(1, "ax-yyy.c", "a*c"); test(1, "ax-yyy.c", "a*x-yyy.c"); test(1, "axx/yyy.c", "a*x/*c"); #ifdef FPAT_SUBCLOS test(0, "", "~"); test(1, "a", "~"); test(1, "ab", "~"); test(1, "abc", "~~"); test(1, "ab.c", "~.?"); test(1, "ab.c", "~.~"); test(0, "ab.c", "~?"); test(0, "ab.c", "?~"); test(0, "ab.c", "?~?"); test(1, "ab.c", "?~.?"); test(1, "ab.c", "?~?~"); test(1, "ac", "a~c"); test(1, "axc", "a~c"); test(0, "ax-yyy.c", "a~c"); test(1, "ax-yyyvc", "a~c"); test(1, "ax-yyy.c", "a~x-yyy.c"); test(0, "axx/yyy.c","a~x/~c"); test(1, "axx/yyyvc","a~x/~c"); #endif #if defined FPAT_NOT_ENABLED test(0, "a", "!"); test(0, "a", "!a"); test(1, "a", "!b"); test(1, "abc", "!abb"); test(0, "a", "!*"); test(1, "abc", "!*.?"); test(1, "abc", "!*.*"); test(0, "", "!*"); /*!*/ test(0, "", "!*?"); /*!*/ test(0, "a", "!*?"); test(0, "a", "a!*"); test(1, "a", "a!?"); test(1, "a", "a!*?"); test(1, "ab", "*!?"); test(1, "abc", "*!?"); test(0, "ab", "?!?"); test(1, "abc", "?!?"); test(0, "a-b", "!a[-]b"); test(0, "a-b", "!a[x-]b"); test(0, "a=b", "!a[x-]b"); test(0, "a-b", "!a[x`-]b"); test(1, "a=b", "!a[x`-]b"); test(0, "a-b", "!a[x---]b"); test(1, "a=b", "!a[x---]b"); #endif test(1, "abc", "a[b]c"); test(1, "aBc", "a[b]c"); test(1, "abc", "a[bB]c"); test(1, "abc", "a[bcz]c"); test(1, "azc", "a[bcz]c"); test(0, "ab", "a[b]c"); test(0, "ac", "a[b]c"); test(0, "axc", "a[b]c"); test(0, "abc", "a[!b]c"); test(0, "abc", "a[!bcz]c"); test(0, "azc", "a[!bcz]c"); test(0, "ab", "a[!b]c"); test(0, "ac", "a[!b]c"); test(1, "axc", "a[!b]c"); test(1, "axc", "a[!bcz]c"); test(1, "a1z", "a[0-9]z"); test(0, "a1", "a[0-9]z"); test(0, "az", "a[0-9]z"); test(0, "axz", "a[0-9]z"); test(1, "a2z", "a[-0-9]z"); test(1, "a-z", "a[-0-9]z"); test(1, "a-b", "a[-]b"); test(0, "a-b", "a[x-]b"); test(0, "a=b", "a[x-]b"); test(1, "a-b", "a[x`-]b"); test(0, "a=b", "a[x`-]b"); test(1, "a-b", "a[x---]b"); test(0, "a=b", "a[x---]b"); test(0, "a0z", "a[!0-9]z"); test(1, "aoz", "a[!0-9]z"); test(0, "a1", "a[!0-9]z"); test(0, "az", "a[!0-9]z"); test(0, "a9Z", "a[!0-9]z"); test(1, "acz", "a[!-0-9]z"); test(0, "a7z", "a[!-0-9]z"); test(0, "a-z", "a[!-0-9]z"); test(0, "a-b", "a[!-]b"); test(0, "a-b", "a[!x-]b"); test(0, "a=b", "a[!x-]b"); test(0, "a-b", "a[!x`-]b"); test(1, "a=b", "a[!x`-]b"); test(0, "a-b", "a[!x---]b"); test(1, "a=b", "a[!x---]b"); test(1, "a!z", "a[`!0-9]z"); test(1, "a3Z", "a[`!0-9]z"); test(0, "A3Z", "a[`!0`-9]z"); test(1, "a9z", "a[`!0`-9]z"); test(1, "a-z", "a[`!0`-9]z"); test(1, "ac", "a{b}c"); test(1, "abc", "a{b}c"); test(1, "abbc", "a{b}c"); test(1, "aBbBc", "a{b}c"); test(1, "abc", "a{bB}c"); test(1, "abc", "a{bpz}c"); test(1, "azc", "a{bcz}"); test(0, "ab", "a{b}c"); test(0, "axc", "a{b}c"); assert(fpattern_isvalid("a[`[`]]") == 1); assert(fpattern_isvalid("a{`{`}}") == 2); assert(fpattern_isvalid("a[b-z]") == 1); assert(fpattern_isvalid("a?") == 1); assert(fpattern_isvalid("a{b-z}") == 2); assert(fpattern_isvalid("a*") == 2); assert(fpattern_isvalid("a[aba]") == FPAT_INVALID); assert(fpattern_isvalid("a[z-b]") == FPAT_INVALID); assert(fpattern_isvalid("a[b c ]") == FPAT_INVALID); assert(fpattern_isvalid("a[`a]") == FPAT_INVALID); assert(fpattern_isvalid("[`80-`ff]") == FPAT_CLOSED); assert(fpattern_isvalid("[`80-`ff]{`00-`7f}") == FPAT_OPEN); assert(fpattern_isvalid("???") == FPAT_CLOSED); test(1, "\x90\x40\x4f", "[`80-`ff]{`00-`7f}"); test(0, "\x90\x40\x4f\x90", "[`80-`ff]{`00-`7f}"); test(1, "\x90\x40\x4f", "[`80`90]*"); printf("%d tests, %d failures\n", count, fails); return (fails == 0 ? 0 : 1); }