2.9.2:
------
+All:
+
+- Added "rest" argument to wxString::Before{First,Last}().
+
All (GUI):
- Added wxRichMessageDialog (Rickard Westerlund, GSoC 2010 project).
// get last nCount characters
wxString Right(size_t nCount) const;
// get all characters before the first occurrence of ch
- // (returns the whole string if ch not found)
- wxString BeforeFirst(wxUniChar ch) const;
+ // (returns the whole string if ch not found) and also put everything
+ // following the first occurrence of ch into rest if it's non-NULL
+ wxString BeforeFirst(wxUniChar ch, wxString *rest = NULL) const;
// get all characters before the last occurrence of ch
- // (returns empty string if ch not found)
- wxString BeforeLast(wxUniChar ch) const;
+ // (returns empty string if ch not found) and also put everything
+ // following the last occurrence of ch into rest if it's non-NULL
+ wxString BeforeLast(wxUniChar ch, wxString *rest = NULL) const;
// get all characters after the first occurrence of ch
// (returns empty string if ch not found)
wxString AfterFirst(wxUniChar ch) const;
/**
Gets all characters before the first occurrence of @e ch.
Returns the whole string if @a ch is not found.
+
+ @param ch The character to look for.
+ @param rest Filled with the part of the string following the first
+ occurrence of @a ch or cleared if it was not found. The same string
+ is returned by AfterFirst() but it is more efficient to use this
+ output parameter if both the "before" and "after" parts are needed
+ than calling both functions one after the other. This parameter is
+ available in wxWidgets version 2.9.2 and later only.
+ @return Part of the string before the first occurrence of @a ch.
*/
- wxString BeforeFirst(wxUniChar ch) const;
+ wxString BeforeFirst(wxUniChar ch, wxString *rest = NULL) const;
/**
Gets all characters before the last occurrence of @e ch.
Returns the empty string if @a ch is not found.
+
+ @param ch The character to look for.
+ @param rest Filled with the part of the string following the last
+ occurrence of @a ch or the copy of this string if it was not found.
+ The same string is returned by AfterLast() but it is more efficient
+ to use this output parameter if both the "before" and "after" parts
+ are needed than calling both functions one after the other. This
+ parameter is available in wxWidgets version 2.9.2 and later only.
+ @return Part of the string before the last occurrence of @a ch.
*/
- wxString BeforeLast(wxUniChar ch) const;
+ wxString BeforeLast(wxUniChar ch, wxString *rest = NULL) const;
//@}
// get all characters before the first occurrence of ch
// (returns the whole string if ch not found)
-wxString wxString::BeforeFirst(wxUniChar ch) const
+wxString wxString::BeforeFirst(wxUniChar ch, wxString *rest) const
{
int iPos = Find(ch);
if ( iPos == wxNOT_FOUND )
- iPos = length();
+ {
+ iPos = length();
+ if ( rest )
+ rest->clear();
+ }
+ else
+ {
+ if ( rest )
+ rest->assign(*this, iPos + 1, npos);
+ }
+
return wxString(*this, 0, iPos);
}
/// get all characters before the last occurrence of ch
/// (returns empty string if ch not found)
-wxString wxString::BeforeLast(wxUniChar ch) const
+wxString wxString::BeforeLast(wxUniChar ch, wxString *rest) const
{
wxString str;
int iPos = Find(ch, true);
- if ( iPos != wxNOT_FOUND && iPos != 0 )
- str = wxString(c_str(), iPos);
+ if ( iPos != wxNOT_FOUND )
+ {
+ if ( iPos != 0 )
+ str.assign(*this, 0, iPos);
+
+ if ( rest )
+ rest->assign(*this, iPos + 1, npos);
+ }
+ else
+ {
+ if ( rest )
+ *rest = *this;
+ }
return str;
}
{
const wxString s(L"letter=\xe9;\xe7a=l\xe0");
- CPPUNIT_ASSERT_EQUAL( "letter", s.BeforeFirst('=') );
- CPPUNIT_ASSERT_EQUAL( s, s.BeforeFirst('!') );
- CPPUNIT_ASSERT_EQUAL( L"letter=\xe9", s.BeforeFirst(';') );
+ wxString r;
+
+ CPPUNIT_ASSERT_EQUAL( "letter", s.BeforeFirst('=', &r) );
+ CPPUNIT_ASSERT_EQUAL( L"\xe9;\xe7a=l\xe0", r );
+
+ CPPUNIT_ASSERT_EQUAL( s, s.BeforeFirst('!', &r) );
+ CPPUNIT_ASSERT_EQUAL( "", r );
+
+ CPPUNIT_ASSERT_EQUAL( L"letter=\xe9", s.BeforeFirst(';', &r) );
+ CPPUNIT_ASSERT_EQUAL( L"\xe7a=l\xe0", r );
+
+
+ CPPUNIT_ASSERT_EQUAL( L"letter=\xe9;\xe7a", s.BeforeLast('=', &r) );
+ CPPUNIT_ASSERT_EQUAL( L"l\xe0", r );
+
+ CPPUNIT_ASSERT_EQUAL( "", s.BeforeLast('!', &r) );
+ CPPUNIT_ASSERT_EQUAL( s, r );
+
+ CPPUNIT_ASSERT_EQUAL( L"letter=\xe9", s.BeforeLast(';', &r) );
+ CPPUNIT_ASSERT_EQUAL( L"\xe7a=l\xe0", r );
- CPPUNIT_ASSERT_EQUAL( L"letter=\xe9;\xe7a", s.BeforeLast('=') );
- CPPUNIT_ASSERT_EQUAL( "", s.BeforeLast('!') );
- CPPUNIT_ASSERT_EQUAL( L"letter=\xe9", s.BeforeLast(';') );
CPPUNIT_ASSERT_EQUAL( L"\xe9;\xe7a=l\xe0", s.AfterFirst('=') );
CPPUNIT_ASSERT_EQUAL( "", s.AfterFirst('!') );
CPPUNIT_ASSERT_EQUAL( L"\xe7a=l\xe0", s.AfterFirst(';') );
+
CPPUNIT_ASSERT_EQUAL( L"l\xe0", s.AfterLast('=') );
CPPUNIT_ASSERT_EQUAL( s, s.AfterLast('!') );
CPPUNIT_ASSERT_EQUAL( L"\xe7a=l\xe0", s.AfterLast(';') );