fix resize() when it's used for truncating a string in UTF-8 build; added test for this bug
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48464 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1087,19 +1087,25 @@ public:
|
||||
|
||||
void resize(size_t nSize, wxUniChar ch = wxT('\0'))
|
||||
{
|
||||
const size_t len = length();
|
||||
if ( nSize == len)
|
||||
return;
|
||||
|
||||
#if wxUSE_UNICODE_UTF8
|
||||
if ( !ch.IsAscii() )
|
||||
if ( nSize < len )
|
||||
{
|
||||
size_t len = length();
|
||||
if ( nSize == len)
|
||||
return;
|
||||
else if ( nSize < len )
|
||||
erase(nSize);
|
||||
else
|
||||
append(nSize - len, ch);
|
||||
// we can't use wxStringImpl::resize() for truncating the string as it
|
||||
// counts in bytes, not characters
|
||||
erase(nSize);
|
||||
return;
|
||||
}
|
||||
|
||||
// we also can't use (presumably more efficient) resize() if we have to
|
||||
// append characters taking more than one byte
|
||||
if ( !ch.IsAscii() )
|
||||
append(nSize - len, ch);
|
||||
else
|
||||
#endif
|
||||
#endif // wxUSE_UNICODE_UTF8
|
||||
m_impl.resize(nSize, (wxStringCharType)ch);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user