added wxRegEx::GetMatch

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11005 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-07-13 17:10:00 +00:00
parent e7208277c1
commit 00e6c2bd41
2 changed files with 21 additions and 2 deletions

View File

@@ -33,7 +33,7 @@
// flags for regex compilation: these can be used with Compile() // flags for regex compilation: these can be used with Compile()
enum enum
{ {
// use extended regex syntax: default // use extended regex syntax (default)
wxRE_EXTENDED = 0, wxRE_EXTENDED = 0,
// use basic RE syntax // use basic RE syntax
@@ -51,7 +51,7 @@ enum
wxRE_NEWLINE = 16, wxRE_NEWLINE = 16,
// default flags // default flags
wxRE_DEFAULT = wxRE_NOSUB | wxRE_EXTENDED wxRE_DEFAULT = wxRE_EXTENDED
}; };
// flags for regex matching: these can be used with Matches() // flags for regex matching: these can be used with Matches()
@@ -97,14 +97,24 @@ public:
// TRUE if matches and FALSE otherwise // TRUE if matches and FALSE otherwise
// //
// flags may be combination of wxRE_NOTBOL and wxRE_NOTEOL // 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; bool Matches(const wxString& str, int flags = 0) const;
// get the start index and the length of the match of the expression // get the start index and the length of the match of the expression
// (index 0) or a bracketed subexpression (index != 0) // (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 // return FALSE if no match or on error
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;
// 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 // replaces the current regular expression in the string pointed to by
// pattern, with the text in replacement and return number of matches // pattern, with the text in replacement and return number of matches
// replaced (maybe 0 if none found) or -1 on error // replaced (maybe 0 if none found) or -1 on error

View File

@@ -315,6 +315,15 @@ bool wxRegEx::GetMatch(size_t *start, size_t *len, size_t index) const
return m_impl->GetMatch(start, len, index); 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 int wxRegEx::Replace(wxString *pattern, const wxString& replacement) const
{ {
wxCHECK_MSG( IsValid(), -1, _T("must successfully Compile() first") ); wxCHECK_MSG( IsValid(), -1, _T("must successfully Compile() first") );