]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/regex.cpp
add wx/unix/private directory
[wxWidgets.git] / src / common / regex.cpp
index c646c915bbb9984593b507c719da71a331a774bc..33458574c99247dfdfbb12b874af393c0e846746 100644 (file)
@@ -61,7 +61,7 @@
 #   ifdef HAVE_RE_SEARCH
 #       define WXREGEX_IF_NEED_LEN(x) ,x
 #       define WXREGEX_USING_RE_SEARCH
-#   else        
+#   else
 #       define WXREGEX_IF_NEED_LEN(x)
 #   endif
 #   if wxUSE_UNICODE
@@ -84,11 +84,22 @@ class wxRegExMatches
 public:
     typedef regmatch_t *match_type;
 
-    wxRegExMatches(size_t n)        { m_matches = new regmatch_t[n]; } 
+    wxRegExMatches(size_t n)        { m_matches = new regmatch_t[n]; }
     ~wxRegExMatches()               { delete [] m_matches; }
 
-    size_t Start(size_t n) const    { return m_matches[n].rm_so; }
-    size_t End(size_t n) const      { return m_matches[n].rm_eo; }
+    // we just use casts here because the fields of regmatch_t struct may be 64
+    // bit but we're limited to size_t in our public API and are not going to
+    // change it because operating on strings longer than 4GB using it is
+    // absolutely impractical anyhow
+    size_t Start(size_t n) const
+    {
+        return wx_truncate_cast(size_t, m_matches[n].rm_so);
+    }
+
+    size_t End(size_t n) const
+    {
+        return wx_truncate_cast(size_t, m_matches[n].rm_eo);
+    }
 
     regmatch_t *get() const         { return m_matches; }
 
@@ -238,7 +249,7 @@ wxString wxRegExImpl::GetErrorMsg(int errorcode, bool badconv) const
 
         (void)wx_regerror(errorcode, &m_RegEx, szcmbError, len);
 
-        szError = wxConvertMB2WX(szcmbError);
+        szError = wxConvLibc.cMB2WX(szcmbError);
         delete [] szcmbError;
     }
     else // regerror() returned 0
@@ -623,21 +634,12 @@ bool wxRegEx::Compile(const wxString& expr, int flags)
     return true;
 }
 
-bool wxRegEx::Matches(const wxChar *str, int flags, size_t len) const
-{
-    wxCHECK_MSG( IsValid(), false, _T("must successfully Compile() first") );
-    (void)len;
-
-    return m_impl->Matches(WXREGEX_CHAR(str), flags WXREGEX_IF_NEED_LEN(len));
-}
-
-bool wxRegEx::Matches(const wxChar *str, int flags) const
+bool wxRegEx::Matches(const wxString& str, int flags) const
 {
     wxCHECK_MSG( IsValid(), false, _T("must successfully Compile() first") );
 
-    return m_impl->Matches(WXREGEX_CHAR(str),
-                           flags
-                           WXREGEX_IF_NEED_LEN(wxStrlen(str)));
+    return m_impl->Matches(WXREGEX_CHAR(str), flags
+                            WXREGEX_IF_NEED_LEN(str.length()));
 }
 
 bool wxRegEx::GetMatch(size_t *start, size_t *len, size_t index) const