Exemple #1
0
static bool recursiveMatch(string str, int sx, string pattern, int px) {
   int slen, plen, i;
   char pch, sch;
   bool match, invert;

   slen = stringLength(str);
   plen = stringLength(pattern);
   if (px == plen) return (sx == slen);
   pch = pattern[px];
   if (pch == '*') {
      for (i = sx; i <= slen; i++) {
         if (recursiveMatch(str, i, pattern, px + 1)) return true;
      }
      return false;
   }
   if (sx == slen) return false;
   sch = str[sx];
   if (pch == '[') {
      match = false;
      invert = false;
      px++;
      if (px == plen) {
         error("matchFilenamePattern: missing ]");
      }
      if (pattern[px] == '^') {
         px++;
         invert = true;
      }
      while (px < plen && pattern[px] != ']') {
         if (px + 2 < plen && pattern[px + 1] == '-') {
            match |= (sch >= pattern[px] && sch <= pattern[px + 2]);
            px += 3;
         } else {
            match |= (sch == pattern[px]);
            px++;
         }
      }
      if (px == plen) {
         error("matchFilenamePattern: missing ]");
      }
      if (match == invert) return false;
   } else if (pch != '?') {
      if (pch != sch) return false;
   }
   return recursiveMatch(str, sx + 1, pattern, px + 1);
}
bool matchFilenamePattern(const std::string& filename, const std::string& pattern) {
    return recursiveMatch(filename, 0, pattern, 0);
}
WebPathSegment* WebPathSegment::match(const string &path)
{
  vector<string> segmentList = StringUtil::split(path, "/");  
  return recursiveMatch(segmentList);
}
Exemple #4
0
bool matchFilenamePattern(string filename, string pattern) {
   return recursiveMatch(filename, 0, pattern, 0);
}