From 00e6c2bd41efbbdd158c9fb609450ebe001a27cc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 13 Jul 2001 17:10:00 +0000 Subject: [PATCH] added wxRegEx::GetMatch git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11005 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/regex.h | 14 ++++++++++++-- src/common/regex.cpp | 9 +++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/wx/regex.h b/include/wx/regex.h index 5927f583f3..70443b2964 100644 --- a/include/wx/regex.h +++ b/include/wx/regex.h @@ -33,7 +33,7 @@ // flags for regex compilation: these can be used with Compile() enum { - // use extended regex syntax: default + // use extended regex syntax (default) wxRE_EXTENDED = 0, // use basic RE syntax @@ -51,7 +51,7 @@ enum wxRE_NEWLINE = 16, // default flags - wxRE_DEFAULT = wxRE_NOSUB | wxRE_EXTENDED + wxRE_DEFAULT = wxRE_EXTENDED }; // flags for regex matching: these can be used with Matches() @@ -97,14 +97,24 @@ public: // TRUE if matches and FALSE otherwise // // flags may be combination of wxRE_NOTBOL and wxRE_NOTEOL + // + // may only be called after successful call to Compile() bool Matches(const wxString& str, int flags = 0) const; // get the start index and the length of the match of the expression // (index 0) or a bracketed subexpression (index != 0) // + // may only be called after successful call to Matches() + // // return FALSE if no match or on error bool GetMatch(size_t *start, size_t *len, size_t index = 0) const; + // return the part of string corresponding to the match, empty string is + // returned if match failed + // + // may only be called after successful call to Matches() + wxString GetMatch(const wxString& text, size_t index = 0) const; + // replaces the current regular expression in the string pointed to by // pattern, with the text in replacement and return number of matches // replaced (maybe 0 if none found) or -1 on error diff --git a/src/common/regex.cpp b/src/common/regex.cpp index dcd016f272..ec57e48df3 100644 --- a/src/common/regex.cpp +++ b/src/common/regex.cpp @@ -315,6 +315,15 @@ bool wxRegEx::GetMatch(size_t *start, size_t *len, size_t index) const return m_impl->GetMatch(start, len, index); } +wxString wxRegEx::GetMatch(const wxString& text, size_t index) const +{ + size_t start, len; + if ( !GetMatch(&start, &len, index) ) + return wxEmptyString; + + return text.Mid(start, len); +} + int wxRegEx::Replace(wxString *pattern, const wxString& replacement) const { wxCHECK_MSG( IsValid(), -1, _T("must successfully Compile() first") ); -- 2.45.2