- switch ( *pszMask )
- {
- case _T('?'):
- pattern += _T('.');
- break;
-
- case _T('*'):
- pattern += _T(".*");
- break;
-
- case _T('^'):
- case _T('.'):
- case _T('$'):
- case _T('('):
- case _T(')'):
- case _T('|'):
- case _T('+'):
- case _T('\\'):
- // these characters are special in a RE, quote them
- // (however note that we don't quote '[' and ']' to allow
- // using them for Unix shell like matching)
- pattern += _T('\\');
- // fall through
-
- default:
- pattern += *pszMask;
- }
-
- pszMask++;
- }
- pattern += _T('$');
-
- // and now use it
- return wxRegEx(pattern, wxRE_NOSUB | wxRE_EXTENDED).Matches(c_str());
-#else // !wxUSE_REGEX
- // TODO: this is, of course, awfully inefficient...
-
- // the char currently being checked
- const wxChar *pszTxt = c_str();
-
- // the last location where '*' matched
- const wxChar *pszLastStarInText = NULL;
- const wxChar *pszLastStarInMask = NULL;
-
-match:
- for ( ; *pszMask != wxT('\0'); pszMask++, pszTxt++ ) {
- switch ( *pszMask ) {
- case wxT('?'):
- if ( *pszTxt == wxT('\0') )
- return FALSE;
-
- // pszTxt and pszMask will be incremented in the loop statement
-
- break;
-
- case wxT('*'):
- {
- // remember where we started to be able to backtrack later
- pszLastStarInText = pszTxt;
- pszLastStarInMask = pszMask;
-
- // ignore special chars immediately following this one
- // (should this be an error?)
- while ( *pszMask == wxT('*') || *pszMask == wxT('?') )
- pszMask++;
-
- // if there is nothing more, match
- if ( *pszMask == wxT('\0') )
- return TRUE;
-
- // are there any other metacharacters in the mask?
- size_t uiLenMask;
- const wxChar *pEndMask = wxStrpbrk(pszMask, wxT("*?"));
-
- if ( pEndMask != NULL ) {
- // we have to match the string between two metachars
- uiLenMask = pEndMask - pszMask;
- }
- else {
- // we have to match the remainder of the string
- uiLenMask = wxStrlen(pszMask);
- }
-
- wxString strToMatch(pszMask, uiLenMask);
- const wxChar* pMatch = wxStrstr(pszTxt, strToMatch);
- if ( pMatch == NULL )
- return FALSE;
-
- // -1 to compensate "++" in the loop
- pszTxt = pMatch + uiLenMask - 1;
- pszMask += uiLenMask - 1;
- }
- break;
-
- default:
- if ( *pszMask != *pszTxt )
- return FALSE;
- break;