]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/string.cpp
applied patch 432814: saving BMP in 1, 4 and 8 bpp
[wxWidgets.git] / src / common / string.cpp
index 902b9a5af744f21f6dc53b9310b4c108f203ed42..9c015019948c344720dbb05cedb433196dede951 100644 (file)
@@ -38,6 +38,8 @@
   #include "wx/thread.h"
 #endif
 
+#include "wx/regex.h"   // for wxString::Matches()
+
 #include <ctype.h>
 #include <string.h>
 #include <stdlib.h>
@@ -589,6 +591,7 @@ wxString& wxString::operator=(wxChar ch)
   return *this;
 }
 
+
 // assigns C string
 wxString& wxString::operator=(const wxChar *psz)
 {
@@ -1456,6 +1459,49 @@ int wxString::PrintfV(const wxChar* pszFormat, va_list argptr)
 // 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
@@ -1539,6 +1585,7 @@ match:
   }
 
   return FALSE;
+#endif // wxUSE_REGEX/!wxUSE_REGEX
 }
 
 // Count the number of chars