added wxRegEx::GetMatchCount (patch 938995)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26904 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2004-04-21 20:14:14 +00:00
parent c3a404b090
commit 86b79b93fb
3 changed files with 40 additions and 4 deletions

View File

@@ -170,6 +170,16 @@ May only be called after successful call to \helpref{Matches()}{wxregexmatches}
and only if {\tt wxRE\_NOSUB} was {\bf not} used in and only if {\tt wxRE\_NOSUB} was {\bf not} used in
\helpref{Compile()}{wxregexcompile}. \helpref{Compile()}{wxregexcompile}.
\membersection{wxRegEx::GetMatchCount}\label{wxregexgetmatchcount}
\constfunc{size\_t}{GetMatchCount}{\void}
Returns the size of the array of matches, i.e. the number of bracketed
subexpressions plus one for the expression itself, or $0$ on error.
May only be called after successful call to \helpref{Compile()}{wxregexcompile}.
and only if {\tt wxRE\_NOSUB} was {\bf not} used.
\membersection{wxRegEx::Matches}\label{wxregexmatches} \membersection{wxRegEx::Matches}\label{wxregexmatches}
\constfunc{bool}{Matches}{\param{const wxChar* }{text}, \param{int }{flags = 0}} \constfunc{bool}{Matches}{\param{const wxChar* }{text}, \param{int }{flags = 0}}

View File

@@ -116,6 +116,12 @@ public:
// may only be called after successful call to Matches() // may only be called after successful call to Matches()
wxString GetMatch(const wxString& text, size_t index = 0) const; wxString GetMatch(const wxString& text, size_t index = 0) const;
// return the size of the array of matches, i.e. the number of bracketed
// subexpressions plus one for the expression itself, or 0 on error.
//
// may only be called after successful call to Compile()
size_t GetMatchCount() 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

@@ -68,6 +68,7 @@ public:
bool Compile(const wxString& expr, int flags = 0); bool Compile(const wxString& expr, int flags = 0);
bool Matches(const wxChar *str, int flags = 0) const; bool Matches(const wxChar *str, int flags = 0) 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;
int Replace(wxString *pattern, const wxString& replacement, int Replace(wxString *pattern, const wxString& replacement,
size_t maxMatches = 0) const; size_t maxMatches = 0) const;
@@ -242,9 +243,12 @@ bool wxRegExImpl::Compile(const wxString& expr, int flags)
{ {
// we know that the previous character is not an unquoted // we know that the previous character is not an unquoted
// backslash because it would have been eaten above, so we // backslash because it would have been eaten above, so we
// have a bar '(' and this indicates a group start for the // have a bare '(' and this indicates a group start for the
// extended syntax // extended syntax. '(?' is used for extensions by perl-
m_nMatches++; // like REs (e.g. advanced), and is not valid for POSIX
// extended, so ignore them always.
if ( cptr[1] != _T('?') )
m_nMatches++;
} }
} }
} }
@@ -306,7 +310,8 @@ bool wxRegExImpl::Matches(const wxChar *str, int flags) const
bool wxRegExImpl::GetMatch(size_t *start, size_t *len, size_t index) const bool wxRegExImpl::GetMatch(size_t *start, size_t *len, size_t index) const
{ {
wxCHECK_MSG( IsValid(), FALSE, _T("must successfully Compile() first") ); wxCHECK_MSG( IsValid(), FALSE, _T("must successfully Compile() first") );
wxCHECK_MSG( m_Matches, FALSE, _T("can't use with wxRE_NOSUB") ); wxCHECK_MSG( m_nMatches, FALSE, _T("can't use with wxRE_NOSUB") );
wxCHECK_MSG( m_Matches, FALSE, _T("must call Matches() first") );
wxCHECK_MSG( index < m_nMatches, FALSE, _T("invalid match index") ); wxCHECK_MSG( index < m_nMatches, FALSE, _T("invalid match index") );
const regmatch_t& match = m_Matches[index]; const regmatch_t& match = m_Matches[index];
@@ -319,6 +324,14 @@ bool wxRegExImpl::GetMatch(size_t *start, size_t *len, size_t index) const
return TRUE; return TRUE;
} }
size_t wxRegExImpl::GetMatchCount() const
{
wxCHECK_MSG( IsValid(), 0, _T("must successfully Compile() first") );
wxCHECK_MSG( m_nMatches, 0, _T("can't use with wxRE_NOSUB") );
return m_nMatches;
}
int wxRegExImpl::Replace(wxString *text, int wxRegExImpl::Replace(wxString *text,
const wxString& replacement, const wxString& replacement,
size_t maxMatches) const size_t maxMatches) const
@@ -487,6 +500,13 @@ wxString wxRegEx::GetMatch(const wxString& text, size_t index) const
return text.Mid(start, len); return text.Mid(start, len);
} }
size_t wxRegEx::GetMatchCount() const
{
wxCHECK_MSG( IsValid(), 0, _T("must successfully Compile() first") );
return m_impl->GetMatchCount();
}
int wxRegEx::Replace(wxString *pattern, int wxRegEx::Replace(wxString *pattern,
const wxString& replacement, const wxString& replacement,
size_t maxMatches) const size_t maxMatches) const