git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11047 
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
   #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>
 // 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
+#endif // wxUSE_REGEX/!wxUSE_REGEX
 }
 
 // Count the number of chars
 }
 
 // Count the number of chars