Get rid of WXREGEX_IF_NEED_LEN() in wxRegEx code

Define wx_regexec() wrapper so that we can just drop the length if it's
not supported in one place, instead of having to use this ugly macro in
several places.

No real changes.
This commit is contained in:
Vadim Zeitlin
2021-07-15 21:54:36 +02:00
parent 8b812a92ae
commit 78546007af

View File

@@ -41,25 +41,27 @@
// WXREGEX_USING_BUILTIN defined when using the built-in regex lib // WXREGEX_USING_BUILTIN defined when using the built-in regex lib
// WXREGEX_USING_RE_SEARCH defined when using re_search in the GNU regex lib // WXREGEX_USING_RE_SEARCH defined when using re_search in the GNU regex lib
// WXREGEX_IF_NEED_LEN() wrap the len parameter only used with the built-in
// or GNU regex
// WXREGEX_CONVERT_TO_MB defined when the regex lib is using chars and // WXREGEX_CONVERT_TO_MB defined when the regex lib is using chars and
// wxChar is wide, so conversion to UTF-8 must be done // wxChar is wide, so conversion to UTF-8 must be done
// //
#ifdef __REG_NOFRONT #ifdef __REG_NOFRONT
# define WXREGEX_USING_BUILTIN # define WXREGEX_USING_BUILTIN
# define WXREGEX_IF_NEED_LEN(x) ,x
#else #else
# ifdef HAVE_RE_SEARCH # ifdef HAVE_RE_SEARCH
# define WXREGEX_IF_NEED_LEN(x) ,x
# define WXREGEX_USING_RE_SEARCH # define WXREGEX_USING_RE_SEARCH
# else # else
# define WXREGEX_IF_NEED_LEN(x) // We can't use length, so just drop it in this wrapper.
inline int
wx_regexec(const regex_t* preg, const char* string, size_t,
size_t nmatch, regmatch_t* pmatch, int eflags)
{
return regexec(preg, string, nmatch, pmatch, eflags);
}
# endif # endif
# if wxUSE_UNICODE # if wxUSE_UNICODE
# define WXREGEX_CONVERT_TO_MB # define WXREGEX_CONVERT_TO_MB
# endif # endif
# define WXREGEX_CHAR(x) (x).mb_str() # define wx_regcomp regcomp
# define wx_regfree regfree # define wx_regfree regfree
# define wx_regerror regerror # define wx_regerror regerror
#endif #endif
@@ -151,8 +153,7 @@ public:
// RE operations // RE operations
bool Compile(const wxString& expr, int flags = 0); bool Compile(const wxString& expr, int flags = 0);
bool Matches(const wxRegChar *str, int flags bool Matches(const wxRegChar *str, int flags, size_t len) const;
WXREGEX_IF_NEED_LEN(size_t len)) const;
bool GetMatch(size_t *start, size_t *len, size_t index = 0) const; bool GetMatch(size_t *start, size_t *len, size_t index = 0) const;
size_t GetMatchCount() const; size_t GetMatchCount() const;
int Replace(wxString *pattern, const wxString& replacement, int Replace(wxString *pattern, const wxString& replacement,
@@ -653,8 +654,8 @@ static int ReSearch(const regex_t *preg,
#endif // WXREGEX_USING_RE_SEARCH #endif // WXREGEX_USING_RE_SEARCH
bool wxRegExImpl::Matches(const wxRegChar *str, bool wxRegExImpl::Matches(const wxRegChar *str,
int flags int flags,
WXREGEX_IF_NEED_LEN(size_t len)) const size_t len) const
{ {
wxCHECK_MSG( IsValid(), false, wxT("must successfully Compile() first") ); wxCHECK_MSG( IsValid(), false, wxT("must successfully Compile() first") );
@@ -683,7 +684,7 @@ bool wxRegExImpl::Matches(const wxRegChar *str,
#elif defined WXREGEX_USING_RE_SEARCH #elif defined WXREGEX_USING_RE_SEARCH
int rc = str ? ReSearch(&self->m_RegEx, str, len, matches, flagsRE) : REG_BADPAT; int rc = str ? ReSearch(&self->m_RegEx, str, len, matches, flagsRE) : REG_BADPAT;
#else #else
int rc = str ? regexec(&self->m_RegEx, str, m_nMatches, matches, flagsRE) : REG_BADPAT; int rc = str ? wx_regexec(&self->m_RegEx, str, m_nMatches, matches, flagsRE) : REG_BADPAT;
#endif #endif
switch ( rc ) switch ( rc )
@@ -777,8 +778,8 @@ int wxRegExImpl::Replace(wxString *text,
#else #else
textstr.data() + matchStart, textstr.data() + matchStart,
#endif #endif
countRepl ? wxRE_NOTBOL : 0 countRepl ? wxRE_NOTBOL : 0,
WXREGEX_IF_NEED_LEN(textlen - matchStart)) ) textlen - matchStart) )
{ {
// the string possibly contains back references: we need to calculate // the string possibly contains back references: we need to calculate
// the replacement text anew after each match // the replacement text anew after each match
@@ -922,8 +923,7 @@ bool wxRegEx::Matches(const wxString& str, int flags) const
const size_t textlen = textstr.length(); const size_t textlen = textstr.length();
#endif #endif
return m_impl->Matches(textstr, flags return m_impl->Matches(textstr, flags, textlen);
WXREGEX_IF_NEED_LEN(textlen));
} }
bool wxRegEx::GetMatch(size_t *start, size_t *len, size_t index) const bool wxRegEx::GetMatch(size_t *start, size_t *len, size_t index) const