Simplify code in wxRegExImpl::Replace()
Check for WXREGEX_CONVERT_TO_MB once and define textstr variable pointing to the string data instead of using it several times. No real changes.
This commit is contained in:
@@ -725,8 +725,9 @@ int wxRegExImpl::Replace(wxString *text,
|
|||||||
const wxChar *textstr = text->c_str();
|
const wxChar *textstr = text->c_str();
|
||||||
size_t textlen = text->length();
|
size_t textlen = text->length();
|
||||||
#else
|
#else
|
||||||
const wxScopedCharBuffer textstr = text->utf8_str();
|
const wxScopedCharBuffer textbuf = text->utf8_str();
|
||||||
size_t textlen = textstr.length();
|
const char* const textstr = textbuf.data();
|
||||||
|
size_t textlen = textbuf.length();
|
||||||
text->clear();
|
text->clear();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -757,14 +758,9 @@ int wxRegExImpl::Replace(wxString *text,
|
|||||||
// note that "^" shouldn't match after the first call to Matches() so we
|
// note that "^" shouldn't match after the first call to Matches() so we
|
||||||
// use wxRE_NOTBOL to prevent it from happening
|
// use wxRE_NOTBOL to prevent it from happening
|
||||||
while ( (!maxMatches || countRepl < maxMatches) &&
|
while ( (!maxMatches || countRepl < maxMatches) &&
|
||||||
Matches(
|
Matches(textstr + matchStart,
|
||||||
#ifndef WXREGEX_CONVERT_TO_MB
|
countRepl ? wxRE_NOTBOL : 0,
|
||||||
textstr + matchStart,
|
textlen - matchStart) )
|
||||||
#else
|
|
||||||
textstr.data() + matchStart,
|
|
||||||
#endif
|
|
||||||
countRepl ? wxRE_NOTBOL : 0,
|
|
||||||
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
|
||||||
@@ -808,14 +804,8 @@ int wxRegExImpl::Replace(wxString *text,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
textNew += wxString(
|
textNew += wxString(textstr + matchStart + start,
|
||||||
#ifndef WXREGEX_CONVERT_TO_MB
|
wxConvUTF8, len);
|
||||||
textstr
|
|
||||||
#else
|
|
||||||
textstr.data()
|
|
||||||
#endif
|
|
||||||
+ matchStart + start,
|
|
||||||
wxConvUTF8, len);
|
|
||||||
|
|
||||||
mayHaveBackrefs = true;
|
mayHaveBackrefs = true;
|
||||||
}
|
}
|
||||||
@@ -841,11 +831,7 @@ int wxRegExImpl::Replace(wxString *text,
|
|||||||
if (result.capacity() < result.length() + start + textNew.length())
|
if (result.capacity() < result.length() + start + textNew.length())
|
||||||
result.reserve(2 * result.length());
|
result.reserve(2 * result.length());
|
||||||
|
|
||||||
#ifndef WXREGEX_CONVERT_TO_MB
|
result.append(wxString(textstr + matchStart, wxConvUTF8, start));
|
||||||
result.append(*text, matchStart, start);
|
|
||||||
#else
|
|
||||||
result.append(wxString(textstr.data() + matchStart, wxConvUTF8, start));
|
|
||||||
#endif
|
|
||||||
matchStart += start;
|
matchStart += start;
|
||||||
result.append(textNew);
|
result.append(textNew);
|
||||||
|
|
||||||
@@ -854,11 +840,7 @@ int wxRegExImpl::Replace(wxString *text,
|
|||||||
matchStart += len;
|
matchStart += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WXREGEX_CONVERT_TO_MB
|
result.append(wxString(textstr + matchStart, wxConvUTF8));
|
||||||
result.append(*text, matchStart, wxString::npos);
|
|
||||||
#else
|
|
||||||
result.append(wxString(textstr.data() + matchStart, wxConvUTF8));
|
|
||||||
#endif
|
|
||||||
*text = result;
|
*text = result;
|
||||||
|
|
||||||
return countRepl;
|
return countRepl;
|
||||||
|
Reference in New Issue
Block a user