Fix wxString::BeforeFirst() when "rest" is the string itself

This didn't work correctly before, but there doesn't seem to be any good
reason to not allow this, as it allows to naturally extract some leading
prefix from a string and it also already worked for BeforeLast(), so
make it work for BeforeFirst() too.
This commit is contained in:
Vadim Zeitlin
2025-01-15 02:19:13 +01:00
parent 01b7d507f2
commit 3a0ac1e14a
3 changed files with 15 additions and 3 deletions
+8
View File
@@ -1127,6 +1127,10 @@ TEST_CASE("StringBeforeAndAfter", "[wxString]")
CHECK( s.BeforeFirst('!', &r) == s );
CHECK( r == "" );
const wxString phrase("Two words apart");
r = phrase;
CHECK( r.BeforeFirst(' ', &r) == "Two" );
CHECK( r == "words apart" );
CHECK( s.BeforeLast('=', &r) == FIRST_PART wxT("=") MIDDLE_PART );
CHECK( r == LAST_PART );
@@ -1134,6 +1138,10 @@ TEST_CASE("StringBeforeAndAfter", "[wxString]")
CHECK( s.BeforeLast('!', &r) == "" );
CHECK( r == s );
r = phrase;
CHECK( r.BeforeLast(' ', &r) == "Two words" );
CHECK( r == "apart" );
CHECK( s.AfterFirst('=') == MIDDLE_PART wxT("=") LAST_PART );
CHECK( s.AfterFirst('!') == "" );