bool Glob::match(TextIterator& itp, const TextIterator& endp, TextIterator& its, const TextIterator& ends) { while (itp != endp) { if (its == ends) { while (itp != endp && *itp == '*') ++itp; break; } switch (*itp) { case '?': ++itp; ++its; break; case '*': if (++itp != endp) { while (its != ends && !matchAfterAsterisk(itp, endp, its, ends)) ++its; return its != ends; } return true; case '[': if (++itp != endp) { bool invert = *itp == '!'; if (invert) ++itp; if (itp != endp) { bool mtch = matchSet(itp, endp, *its++); if ((invert && mtch) || (!invert && !mtch)) return false; break; } } throw SyntaxException("bad range syntax in glob pattern"); case '\\': if (++itp == endp) throw SyntaxException("backslash must be followed by character in glob pattern"); // fallthrough default: if (_options & GLOB_CASELESS) { if (Unicode::toLower(*itp) != Unicode::toLower(*its)) return false; } else { if (*itp != *its) return false; } ++itp; ++its; } } return itp == endp && its == ends; }
bool Glob::match(std::string::const_iterator& itp, const std::string::const_iterator& endp, std::string::const_iterator& its, const std::string::const_iterator& ends) { while (itp != endp) { if (its == ends) { while (itp != endp && *itp == '*') ++itp; break; } switch (*itp) { case '?': ++itp; ++its; break; case '*': if (++itp != endp) { while (its != ends && !matchAfterAsterisk(itp, endp, its, ends)) ++its; return its != ends; } return true; case '[': if (++itp != endp) { bool invert = *itp == '!'; if (invert) ++itp; if (itp != endp) { bool mtch = matchSet(itp, endp, *its++); if (invert && mtch || !invert && !mtch) return false; break; } } throw SyntaxException("bad range syntax in glob pattern"); case '\\': if (++itp == endp) throw SyntaxException("backslash must be followed by character in glob pattern"); // fallthrough default: if (*itp != *its) return false; ++itp; ++its; } } return itp == endp && its == ends; }