]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/regex.cpp
Fixed undeclared identifier compile error.
[wxWidgets.git] / src / common / regex.cpp
index 943fc2c46b4447128ad40dd8b9a5da734b8e0fa0..7f23266dd5d9405eaebc9ec1e94d7e3f494fc909 100644 (file)
@@ -18,7 +18,7 @@
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
     #pragma implementation "regex.h"
 #endif
 
     #include <sys/types.h>
 #endif
 
+#ifndef __WXWINCE__
 #include <regex.h>
+#endif
 
 #include "wx/regex.h"
 
+#ifdef wxUSE_NEW_REGEX
+    #define regerror wx_regerror
+    #define regfree wx_regfree
+#endif
+
 // ----------------------------------------------------------------------------
 // private classes
 // ----------------------------------------------------------------------------
@@ -178,9 +185,15 @@ bool wxRegExImpl::Compile(const wxString& expr, int flags)
     if ( flags & wxRE_NEWLINE )
         flagsRE |= REG_NEWLINE;
 
+
     // compile it
+#if wxUSE_NEW_REGEX
+    int errorcode = wx_regcomp(&m_RegEx, expr, expr.Length(), flagsRE);
+#else
     int errorcode = regcomp(&m_RegEx, expr.mb_str(), flagsRE);
-    if ( errorcode )
+#endif
+
+     if ( errorcode )
     {
         wxLogError(_("Invalid regular expression '%s': %s"),
                    expr.c_str(), GetErrorMsg(errorcode).c_str());
@@ -204,21 +217,24 @@ bool wxRegExImpl::Compile(const wxString& expr, int flags)
             m_nMatches = 1;
 
             // and some more for bracketed subexperessions
-            const wxChar *cptr = expr.c_str();
-            wxChar prev = _T('\0');
-            while ( *cptr != _T('\0') )
+            for ( const wxChar *cptr = expr.c_str(); *cptr; cptr++ )
             {
-                // is this a subexpr start, i.e. "(" for extended regex or
-                // "\(" for a basic one?
-                if ( *cptr == _T('(') &&
-                     (flags & wxRE_BASIC ? prev == _T('\\')
-                                         : prev != _T('\\')) )
+                if ( *cptr == _T('\\') )
                 {
+                    // in basic RE syntax groups are inside \(...\)
+                    if ( *++cptr == _T('(') && (flags & wxRE_BASIC) )
+                    {
+                        m_nMatches++;
+                    }
+                }
+                else if ( *cptr == _T('(') && !(flags & wxRE_BASIC) )
+                {
+                    // we know that the previous character is not an unquoted
+                    // backslash because it would have been eaten above, so we
+                    // have a bar '(' and this indicates a group start for the
+                    // extended syntax
                     m_nMatches++;
                 }
-
-                prev = *cptr;
-                cptr++;
             }
         }
 
@@ -250,7 +266,12 @@ bool wxRegExImpl::Matches(const wxChar *str, int flags) const
     }
 
     // do match it
+#ifdef wxUSE_NEW_REGEX
+       rm_detail_t rd;
+    int rc = wx_regexec(&self->m_RegEx, str, wxStrlen(str), &rd, m_nMatches, m_Matches, flagsRE);
+#else
     int rc = regexec(&self->m_RegEx, wxConvertWX2MB(str), m_nMatches, m_Matches, flagsRE);
+#endif
 
     switch ( rc )
     {