Example #1
0
bool match(wchar *pattern,wchar *string,bool ForceCase)
{
    for (;; ++string)
    {
        wchar stringc=touppercw(*string,ForceCase);
        wchar patternc=touppercw(*pattern++,ForceCase);
        switch (patternc)
        {
        case 0:
            return(stringc==0);
        case '?':
            if (stringc == 0)
                return(false);
            break;
        case '*':
            if (*pattern==0)
                return(true);
            if (*pattern=='.')
            {
                if (pattern[1]=='*' && pattern[2]==0)
                    return(true);
                wchar *dot=strchrw(string,'.');
                if (pattern[1]==0)
                    return (dot==NULL || dot[1]==0);
                if (dot!=NULL)
                {
                    string=dot;
                    if (strpbrkw(pattern,L"*?")==NULL && strchrw(string+1,'.')==NULL)
                        return(mstricompcw(pattern+1,string+1,ForceCase)==0);
                }
            }

            while (*string)
                if (match(pattern,string++,ForceCase))
                    return(true);
            return(false);
        default:
            if (patternc != stringc)
            {
                // Allow "name." mask match "name" and "name.\" match "name\".
                if (patternc=='.' && (stringc==0 || stringc=='\\' || stringc=='.'))
                    return(match(pattern,string,ForceCase));
                else
                    return(false);
            }
            break;
        }
    }
}
Example #2
0
bool match(wchar *pattern,wchar *string)
{
  for (;; ++string)
  {
    wchar stringc=touppercw(*string);
    wchar patternc=touppercw(*pattern++);
    switch (patternc)
    {
      case 0:
        return(stringc==0);
      case '?':
        if (stringc == 0)
          return(false);
        break;
      case '*':
        if (*pattern==0)
          return(true);
        if (*pattern=='.')
        {
          if (pattern[1]=='*' && pattern[2]==0)
            return(true);
          wchar *dot=strchrw(string,'.');
          if (pattern[1]==0)
            return (dot==NULL || dot[1]==0);
          if (dot!=NULL)
          {
            string=dot;
            if (strpbrkw(pattern,L"*?")==NULL && strchrw(string+1,'.')==NULL)
              return(stricompcw(pattern+1,string+1)==0);
          }
        }

        while (*string)
          if (match(pattern,string++))
            return(true);
        return(false);
      default:
        if (patternc != stringc)
          if (patternc=='.' && stringc==0)
            return(match(pattern,string));
          else
            return(false);
        break;
    }
  }
}
Example #3
0
bool IsWildcard(const char *Str,const wchar *StrW)
{
  if (StrW!=NULL && *StrW!=0)
    return(strpbrkw(StrW,L"*?")!=NULL);
  return(Str==NULL ? false:strpbrk(Str,"*?")!=NULL);
}