Allow calling wxStrchr() with a narrow string and wide character.
Calls to wxStrchr(char-string, wide-char) would previously fail if wide character couldn't be converted to a single character in the current locale encoding. Change it to simply return NULL in this case as it's a safe and useful generalization: a narrow string will never contain a wide character not representable in the current locale. Add wxUniChar::GetAsChar() to help with implementing this. Closes #11487. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62738 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -44,6 +44,7 @@ public:
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( CrtTestCase );
|
||||
CPPUNIT_TEST( SetGetEnv );
|
||||
CPPUNIT_TEST( Strchr );
|
||||
CPPUNIT_TEST( Strcmp );
|
||||
CPPUNIT_TEST( Strspn );
|
||||
CPPUNIT_TEST( Strcspn );
|
||||
@@ -52,6 +53,7 @@ private:
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void SetGetEnv();
|
||||
void Strchr();
|
||||
void Strcmp();
|
||||
void Strspn();
|
||||
void Strcspn();
|
||||
@@ -89,6 +91,19 @@ void CrtTestCase::SetGetEnv()
|
||||
#undef TESTVAR_NAME
|
||||
}
|
||||
|
||||
void CrtTestCase::Strchr()
|
||||
{
|
||||
// test that searching for a wide character in a narrow string simply
|
||||
// doesn't find it but doesn't fail with an assert (#11487)
|
||||
const wxUniChar smiley = *wxString::FromUTF8("\xe2\x98\xba").begin();
|
||||
|
||||
CPPUNIT_ASSERT( !wxStrchr("hello", smiley) );
|
||||
|
||||
// but searching for an explicitly wide character does find it
|
||||
CPPUNIT_ASSERT( wxStrchr(wxString::FromUTF8(":-) == \xe2\x98\xba"),
|
||||
static_cast<wchar_t>(smiley)) );
|
||||
}
|
||||
|
||||
void CrtTestCase::Strcmp()
|
||||
{
|
||||
// this code tests if all possible ways of calling wxStrcmp() compile:
|
||||
|
Reference in New Issue
Block a user