]> git.saurik.com Git - wxWidgets.git/commitdiff
fix After{First,Last}() to work for strings with non-ASCII characters in UTF-8 build...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 29 Sep 2008 12:08:44 +0000 (12:08 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 29 Sep 2008 12:08:44 +0000 (12:08 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55944 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/string.cpp
tests/strings/strings.cpp

index 595caf71257daa6259c51b4c006b22304f15a879..573e5073c249c8ed702f7f21bc01eb4f32ed50e4 100644 (file)
@@ -1285,7 +1285,7 @@ wxString wxString::AfterLast(wxUniChar ch) const
   if ( iPos == wxNOT_FOUND )
     str = *this;
   else
-    str = wx_str() + iPos + 1;
+    str.assign(*this, iPos + 1, npos);
 
   return str;
 }
@@ -1308,7 +1308,8 @@ wxString wxString::Left(size_t nCount) const
 wxString wxString::BeforeFirst(wxUniChar ch) const
 {
   int iPos = Find(ch);
-  if ( iPos == wxNOT_FOUND ) iPos = length();
+  if ( iPos == wxNOT_FOUND )
+      iPos = length();
   return wxString(*this, 0, iPos);
 }
 
@@ -1331,7 +1332,7 @@ wxString wxString::AfterFirst(wxUniChar ch) const
   wxString str;
   int iPos = Find(ch);
   if ( iPos != wxNOT_FOUND )
-    str = wx_str() + iPos + 1;
+      str.assign(*this, iPos + 1, npos);
 
   return str;
 }
index a3fec565982508818f4ad3c3db48201d7eb5d01d..3542704e49cea77d7aca63941bbfc617fd94bae2 100644 (file)
@@ -60,6 +60,7 @@ private:
         CPPUNIT_TEST( CStrDataImplicitConversion );
         CPPUNIT_TEST( ExplicitConversion );
         CPPUNIT_TEST( IndexedAccess );
+        CPPUNIT_TEST( BeforeAndAfter );
     CPPUNIT_TEST_SUITE_END();
 
     void String();
@@ -91,6 +92,7 @@ private:
     void CStrDataImplicitConversion();
     void ExplicitConversion();
     void IndexedAccess();
+    void BeforeAndAfter();
 
     DECLARE_NO_COPY_CLASS(StringTestCase)
 };
@@ -841,3 +843,24 @@ void StringTestCase::IndexedAccess()
     CPPUNIT_ASSERT_EQUAL( 'r', s[2] );
 }
 
+void StringTestCase::BeforeAndAfter()
+{
+    const wxString s(L"letter=\u00e9;\u00e7a=l\u00e0");
+
+    CPPUNIT_ASSERT_EQUAL( "letter", s.BeforeFirst('=') );
+    CPPUNIT_ASSERT_EQUAL( s, s.BeforeFirst('!') );
+    CPPUNIT_ASSERT_EQUAL( L"letter=\u00e9", s.BeforeFirst(';') );
+
+    CPPUNIT_ASSERT_EQUAL( L"letter=\u00e9;\u00e7a", s.BeforeLast('=') );
+    CPPUNIT_ASSERT_EQUAL( "", s.BeforeLast('!') );
+    CPPUNIT_ASSERT_EQUAL( L"letter=\u00e9", s.BeforeLast(';') );
+
+    CPPUNIT_ASSERT_EQUAL( L"\u00e9;\u00e7a=l\u00e0", s.AfterFirst('=') );
+    CPPUNIT_ASSERT_EQUAL( "", s.AfterFirst('!') );
+    CPPUNIT_ASSERT_EQUAL( L"\u00e7a=l\u00e0", s.AfterFirst(';') );
+
+    CPPUNIT_ASSERT_EQUAL( L"l\u00e0", s.AfterLast('=') );
+    CPPUNIT_ASSERT_EQUAL( s, s.AfterLast('!') );
+    CPPUNIT_ASSERT_EQUAL( L"\u00e7a=l\u00e0", s.AfterLast(';') );
+}
+