if ( iPos == wxNOT_FOUND )
str = *this;
else
- str = wx_str() + iPos + 1;
+ str.assign(*this, iPos + 1, npos);
return str;
}
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);
}
wxString str;
int iPos = Find(ch);
if ( iPos != wxNOT_FOUND )
- str = wx_str() + iPos + 1;
+ str.assign(*this, iPos + 1, npos);
return str;
}
CPPUNIT_TEST( CStrDataImplicitConversion );
CPPUNIT_TEST( ExplicitConversion );
CPPUNIT_TEST( IndexedAccess );
+ CPPUNIT_TEST( BeforeAndAfter );
CPPUNIT_TEST_SUITE_END();
void String();
void CStrDataImplicitConversion();
void ExplicitConversion();
void IndexedAccess();
+ void BeforeAndAfter();
DECLARE_NO_COPY_CLASS(StringTestCase)
};
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(';') );
+}
+