X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2cdf244521293d49992e208f6db5bbb2469faf69..aff909dd4f5076d56d79f15eaef85549e517ab80:/src/common/regex.cpp?ds=sidebyside diff --git a/src/common/regex.cpp b/src/common/regex.cpp index d608a5773d..bc0faa554e 100644 --- a/src/common/regex.cpp +++ b/src/common/regex.cpp @@ -32,6 +32,7 @@ #include "wx/string.h" #include "wx/log.h" #include "wx/intl.h" + #include "wx/crt.h" #endif //WX_PRECOMP // FreeBSD, Watcom and DMars require this, CW doesn't have nor need it. @@ -56,7 +57,11 @@ #ifdef __REG_NOFRONT # define WXREGEX_USING_BUILTIN # define WXREGEX_IF_NEED_LEN(x) ,x -# define WXREGEX_CHAR(x) x +# if wxUSE_UNICODE +# define WXREGEX_CHAR(x) x.wc_str() +# else +# define WXREGEX_CHAR(x) x.mb_str() +# endif #else # ifdef HAVE_RE_SEARCH # define WXREGEX_IF_NEED_LEN(x) ,x @@ -67,7 +72,7 @@ # if wxUSE_UNICODE # define WXREGEX_CONVERT_TO_MB # endif -# define WXREGEX_CHAR(x) wxConvertWX2MB(x) +# define WXREGEX_CHAR(x) x.mb_str() # define wx_regfree regfree # define wx_regerror regerror #endif @@ -90,16 +95,14 @@ public: // 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, but still check at least in debug + // absolutely impractical anyhow size_t Start(size_t n) const { - wxASSERT_MSG( m_matches[n].rm_so < UINT_MAX, _T("regex offset overflow") ); return wx_truncate_cast(size_t, m_matches[n].rm_so); } size_t End(size_t n) const { - wxASSERT_MSG( m_matches[n].rm_eo < UINT_MAX, _T("regex offset overflow") ); return wx_truncate_cast(size_t, m_matches[n].rm_eo); } @@ -251,7 +254,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 @@ -295,8 +298,11 @@ bool wxRegExImpl::Compile(const wxString& expr, int flags) // compile it #ifdef WXREGEX_USING_BUILTIN bool conv = true; - int errorcode = wx_re_comp(&m_RegEx, expr, expr.length(), flagsRE); + // FIXME-UTF8: use wc_str() after removing ANSI build + int errorcode = wx_re_comp(&m_RegEx, expr.c_str(), expr.length(), flagsRE); #else + // FIXME-UTF8: this is potentially broken, we shouldn't even try it + // and should always use builtin regex library (or PCRE?) const wxWX2MBbuf conv = expr.mbc_str(); int errorcode = conv ? regcomp(&m_RegEx, conv, flagsRE) : REG_BADPAT; #endif @@ -636,21 +642,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