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'))
|
void resize(size_t nSize, wxUniChar ch = wxT('\0'))
|
||||||
{
|
{
|
||||||
|
const size_t len = length();
|
||||||
|
if ( nSize == len)
|
||||||
|
return;
|
||||||
|
|
||||||
#if wxUSE_UNICODE_UTF8
|
#if wxUSE_UNICODE_UTF8
|
||||||
if ( !ch.IsAscii() )
|
if ( nSize < len )
|
||||||
{
|
{
|
||||||
size_t len = length();
|
// we can't use wxStringImpl::resize() for truncating the string as it
|
||||||
if ( nSize == len)
|
// counts in bytes, not characters
|
||||||
return;
|
erase(nSize);
|
||||||
else if ( nSize < len )
|
return;
|
||||||
erase(nSize);
|
|
||||||
else
|
|
||||||
append(nSize - len, ch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
else
|
||||||
#endif
|
#endif // wxUSE_UNICODE_UTF8
|
||||||
m_impl.resize(nSize, (wxStringCharType)ch);
|
m_impl.resize(nSize, (wxStringCharType)ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -488,6 +488,11 @@ void StdStringTestCase::StdResize()
|
|||||||
CPPUNIT_ASSERT( s2 == _T("abcABCdefD") );
|
CPPUNIT_ASSERT( s2 == _T("abcABCdefD") );
|
||||||
CPPUNIT_ASSERT( s3 == _T("abcABCdefDEF ") );
|
CPPUNIT_ASSERT( s3 == _T("abcABCdefDEF ") );
|
||||||
CPPUNIT_ASSERT( s4 == _T("abcABCdefDEFWW") );
|
CPPUNIT_ASSERT( s4 == _T("abcABCdefDEFWW") );
|
||||||
|
|
||||||
|
wxString s =
|
||||||
|
wxString::FromUTF8("\xd0\x9f\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82");
|
||||||
|
s.resize(3);
|
||||||
|
WX_ASSERT_STR_EQUAL("\xd0\x9f\xd1\x80\xd0\xb8", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StdStringTestCase::StdRiter()
|
void StdStringTestCase::StdRiter()
|
||||||
|
Reference in New Issue
Block a user