]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/string.cpp
We use native paths now in wxWindows. On the Mac, too.
[wxWidgets.git] / src / common / string.cpp
index 902b9a5af744f21f6dc53b9310b4c108f203ed42..beb618873d0d3abab43e547f6d1d5363a2fcd974 100644 (file)
@@ -38,6 +38,8 @@
   #include "wx/thread.h"
 #endif
 
   #include "wx/thread.h"
 #endif
 
+#include "wx/regex.h"   // for wxString::Matches()
+
 #include <ctype.h>
 #include <string.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
 #include <stdlib.h>
@@ -1456,6 +1458,49 @@ int wxString::PrintfV(const wxChar* pszFormat, va_list argptr)
 // of them)
 bool wxString::Matches(const wxChar *pszMask) const
 {
 // of them)
 bool wxString::Matches(const wxChar *pszMask) const
 {
+#if wxUSE_REGEX
+    // first translate the shell-like mask into a regex
+    wxString pattern;
+    pattern.reserve(wxStrlen(pszMask));
+
+    pattern += _T('^');
+    while ( *pszMask )
+    {
+        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
   // TODO: this is, of course, awfully inefficient...
 
   // the char currently being checked
@@ -1539,6 +1584,7 @@ match:
   }
 
   return FALSE;
   }
 
   return FALSE;
+#endif // wxUSE_REGEX/!wxUSE_REGEX
 }
 
 // Count the number of chars
 }
 
 // Count the number of chars