git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36182
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
\constfunc{bool}{Matches}{\param{const wxChar* }{text}, \param{int }{flags = 0}}
\constfunc{bool}{Matches}{\param{const wxChar* }{text}, \param{int }{flags = 0}}
+\constfunc{bool}{Matches}{\param{const wxChar* }{text}, \param{int }{flags}, \param{size\_t }{len}}
+
+\constfunc{bool}{Matches}{\param{const wxString\& }{text}, \param{int }{flags = 0}}
+
Matches the precompiled regular expression against the string {\it text},
returns {\tt true} if matches and {\tt false} otherwise.
Matches the precompiled regular expression against the string {\it text},
returns {\tt true} if matches and {\tt false} otherwise.
-Flags may be combination of {\tt wxRE\_NOTBOL} and {\tt wxRE\_NOTEOL}.
+{\it Flags} may be combination of {\tt wxRE\_NOTBOL} and {\tt wxRE\_NOTEOL}.
+
+System regex libraries always assume the text being searched is null
+terminated and any length given is ignored.
+
+When using the built-in regex library, the first overload obtains the length
+of the string using wxStrlen, the second from the {\it len} parameter and the
+third from the length of the {\it wxString}.
May only be called after successful call to \helpref{Compile()}{wxregexcompile}.
May only be called after successful call to \helpref{Compile()}{wxregexcompile}.
// true if matches and false otherwise
//
// flags may be combination of wxRE_NOTBOL and wxRE_NOTEOL
// true if matches and false otherwise
//
// flags may be combination of wxRE_NOTBOL and wxRE_NOTEOL
+ // len may be the length of text (ignored except by built-in regex lib)
//
// may only be called after successful call to Compile()
bool Matches(const wxChar *text, int flags = 0) const;
//
// may only be called after successful call to Compile()
bool Matches(const wxChar *text, int flags = 0) const;
+ bool Matches(const wxChar *text, int flags, size_t len) const;
+ bool Matches(const wxString& text, int flags = 0) const
+ { return Matches(text.c_str(), flags, text.length()); }
// get the start index and the length of the match of the expression
// (index 0) or a bracketed subexpression (index != 0)
// get the start index and the length of the match of the expression
// (index 0) or a bracketed subexpression (index != 0)
#include <regex.h>
#include "wx/regex.h"
#include <regex.h>
#include "wx/regex.h"
-// defined when the regex lib uses 'char' but 'wxChar' is wide
-#if wxUSE_UNICODE && !defined(__REG_NOFRONT)
-# define WXREGEX_CONVERT_TO_MB
+// WXREGEX_USING_BUILTIN defined when using the built-in regex lib
+// WXREGEX_BUILTIN_ONLY() wrap a parameter only used with the built-in regex
+// WXREGEX_CONVERT_TO_MB indicates when the regex lib is using chars and
+// wxChar is wide, so conversion must be done
+#ifdef __REG_NOFRONT
+# define WXREGEX_USING_BUILTIN
+# define WXREGEX_BUILTIN_ONLY(x) ,x
+#else
+# define WXREGEX_BUILTIN_ONLY(x)
+# if wxUSE_UNICODE
+# define WXREGEX_CONVERT_TO_MB
+# endif
#endif
// ----------------------------------------------------------------------------
#endif
// ----------------------------------------------------------------------------
// RE operations
bool Compile(const wxString& expr, int flags = 0);
// RE operations
bool Compile(const wxString& expr, int flags = 0);
- bool Matches(const wxRegChar *str, int flags, size_t len) const;
+ bool Matches(const wxRegChar *str, int flags
+ WXREGEX_BUILTIN_ONLY(size_t len)) const;
bool GetMatch(size_t *start, size_t *len, size_t index = 0) const;
size_t GetMatchCount() const;
int Replace(wxString *pattern, const wxString& replacement,
bool GetMatch(size_t *start, size_t *len, size_t index = 0) const;
size_t GetMatchCount() const;
int Replace(wxString *pattern, const wxString& replacement,
flagsRE |= REG_NEWLINE;
// compile it
flagsRE |= REG_NEWLINE;
// compile it
+#ifdef WXREGEX_USING_BUILTIN
bool conv = true;
int errorcode = wx_re_comp(&m_RegEx, expr, expr.length(), flagsRE);
#else
bool conv = true;
int errorcode = wx_re_comp(&m_RegEx, expr, expr.length(), flagsRE);
#else
-bool wxRegExImpl::Matches(const wxRegChar *str, int flags, size_t len) const
+bool wxRegExImpl::Matches(const wxRegChar *str,
+ int flags
+ WXREGEX_BUILTIN_ONLY(size_t len)) const
{
wxCHECK_MSG( IsValid(), false, _T("must successfully Compile() first") );
{
wxCHECK_MSG( IsValid(), false, _T("must successfully Compile() first") );
+#ifdef WXREGEX_USING_BUILTIN
int rc = wx_re_exec(&self->m_RegEx, str, len, NULL, m_nMatches, m_Matches, flagsRE);
#else
int rc = str ? regexec(&self->m_RegEx, str, m_nMatches, m_Matches, flagsRE) : REG_BADPAT;
int rc = wx_re_exec(&self->m_RegEx, str, len, NULL, m_nMatches, m_Matches, flagsRE);
#else
int rc = str ? regexec(&self->m_RegEx, str, m_nMatches, m_Matches, flagsRE) : REG_BADPAT;
// use wxRE_NOTBOL to prevent it from happening
while ( (!maxMatches || countRepl < maxMatches) &&
Matches(textstr + matchStart,
// use wxRE_NOTBOL to prevent it from happening
while ( (!maxMatches || countRepl < maxMatches) &&
Matches(textstr + matchStart,
- countRepl ? wxRE_NOTBOL : 0,
- textlen - matchStart) )
+ countRepl ? wxRE_NOTBOL : 0
+ WXREGEX_BUILTIN_ONLY(textlen - matchStart)) )
{
// the string possibly contains back references: we need to calculate
// the replacement text anew after each match
{
// the string possibly contains back references: we need to calculate
// the replacement text anew after each match
+bool wxRegEx::Matches(const wxChar *str, int flags, size_t len) const
+{
+ wxCHECK_MSG( IsValid(), false, _T("must successfully Compile() first") );
+ (void)len;
+
+#ifdef WXREGEX_CONVERT_TO_MB
+ return m_impl->Matches(wxConvertWX2MB(str), flags);
+#else
+ return m_impl->Matches(str, flags WXREGEX_BUILTIN_ONLY(len));
+#endif
+}
+
bool wxRegEx::Matches(const wxChar *str, int flags) const
{
wxCHECK_MSG( IsValid(), false, _T("must successfully Compile() first") );
bool wxRegEx::Matches(const wxChar *str, int flags) const
{
wxCHECK_MSG( IsValid(), false, _T("must successfully Compile() first") );
-#ifndef WXREGEX_CONVERT_TO_MB
- return m_impl->Matches(str, flags, wxStrlen(str));
+#ifdef WXREGEX_CONVERT_TO_MB
+ return m_impl->Matches(wxConvertWX2MB(str), flags);
- return m_impl->Matches(wxConvertWX2MB(str), flags, wxStrlen(str));
+ return m_impl->Matches(str, flags WXREGEX_BUILTIN_ONLY(wxStrlen(str)));