rewrite FilterInValue() using iterators, this results iin 12x performance improvement in UTF-8 build

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47577 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-07-20 01:03:33 +00:00
parent c225b981b6
commit cdbcd6c12f

View File

@@ -1961,13 +1961,28 @@ int CompareGroups(wxFileConfigGroup *p1, wxFileConfigGroup *p2)
static wxString FilterInValue(const wxString& str)
{
wxString strResult;
strResult.Alloc(str.Len());
if ( str.empty() )
return strResult;
bool bQuoted = !str.empty() && str[0] == '"';
strResult.reserve(str.length());
for ( size_t n = bQuoted ? 1 : 0; n < str.Len(); n++ ) {
if ( str[n] == wxT('\\') ) {
switch ( str[++n].GetValue() ) {
wxString::const_iterator i = str.begin();
const bool bQuoted = *i == '"';
if ( bQuoted )
++i;
for ( const wxString::const_iterator end = str.end(); i != end; ++i )
{
if ( *i == wxT('\\') )
{
if ( ++i == end )
{
wxLogWarning(_("trailing backslash ignored in '%s'"), str.c_str());
break;
}
switch ( (*i).GetValue() )
{
case wxT('n'):
strResult += wxT('\n');
break;
@@ -1989,12 +2004,16 @@ static wxString FilterInValue(const wxString& str)
break;
}
}
else {
if ( str[n] != wxT('"') || !bQuoted )
strResult += str[n];
else if ( n != str.Len() - 1 ) {
else // not a backslash
{
if ( *i != wxT('"') || !bQuoted )
{
strResult += *i;
}
else if ( i != end - 1 )
{
wxLogWarning(_("unexpected \" at position %d in '%s'."),
n, str.c_str());
i - str.begin(), str.c_str());
}
//else: it's the last quote of a quoted string, ok
}