hrev52348 adds 2 changesets to branch 'master'
old head: 79187c3c423ba727fba96b67be16295f6f0fc7fb
new head: f436972c145055b1a810c597a35e394cf73ef2d2
overview:
https://git.haiku-os.org/haiku/log/?qt=range&q=f436972c1450+%5E79187c3c423b
----------------------------------------------------------------------------
38a133eb8a34: StringReplaceTest: Add (failing) invocations of Replace*() with
NULL "to".
BeOS R5 treats NULL passed as the "replace with" argument as if it were
an empty string. Our BString currently does nothing.
Change-Id: I54b661e4ea8335ce531e6b6e3de2095a41112cd7
Reviewed-on: https://review.haiku-os.org/571
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
f436972c1450: BString: Treat NULL passed as replaceWith as an empty string.
Fixes the tests added in the previous commit, and also #8552.
Change-Id: Idf9459474bc66054f94cf66065ed6fcf9c60cece
Reviewed-on: https://review.haiku-os.org/572
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
[ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]
----------------------------------------------------------------------------
2 files changed, 54 insertions(+), 10 deletions(-)
src/kits/support/String.cpp | 24 +++++++-----
.../kits/support/bstring/StringReplaceTest.cpp | 40 ++++++++++++++++++++
############################################################################
Commit: 38a133eb8a349ed5785f088ecaa2efc9c1f17cb8
URL: https://git.haiku-os.org/haiku/commit/?id=38a133eb8a34
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Sun Sep 16 17:53:05 2018 UTC
Committer: waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sun Sep 16 17:57:02 2018 UTC
StringReplaceTest: Add (failing) invocations of Replace*() with NULL "to".
BeOS R5 treats NULL passed as the "replace with" argument as if it were
an empty string. Our BString currently does nothing.
Change-Id: I54b661e4ea8335ce531e6b6e3de2095a41112cd7
Reviewed-on: https://review.haiku-os.org/571
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
----------------------------------------------------------------------------
diff --git a/src/tests/kits/support/bstring/StringReplaceTest.cpp
b/src/tests/kits/support/bstring/StringReplaceTest.cpp
index 8e91bf3f0d..f7e80e31aa 100644
--- a/src/tests/kits/support/bstring/StringReplaceTest.cpp
+++ b/src/tests/kits/support/bstring/StringReplaceTest.cpp
@@ -108,6 +108,12 @@ StringReplaceTest::PerformTest(void)
"she sells sea shells on the seashore") == 0);
delete str1;
+ NextSubTest();
+ str1 = new BString("Error moving \"%name\"");
+ str1->ReplaceFirst("%name", NULL);
+ CPPUNIT_ASSERT(strcmp(str1->String(), "Error moving \"\"") == 0);
+ delete str1;
+
// &ReplaceLast(const char*, const char*)
NextSubTest();
str1 = new BString("she sells sea shells on the seashore");
@@ -123,6 +129,13 @@ StringReplaceTest::PerformTest(void)
"she sells sea shells on the seashore") == 0);
delete str1;
+ NextSubTest();
+ str1 = new BString("she sells sea shells on the seashore");
+ str1->ReplaceLast("sea", NULL);
+ CPPUNIT_ASSERT(strcmp(str1->String(),
+ "she sells sea shells on the shore") == 0);
+ delete str1;
+
// &ReplaceAll(const char*, const char*, int32)
NextSubTest();
str1 = new BString("abc abc abc");
@@ -136,6 +149,12 @@ StringReplaceTest::PerformTest(void)
CPPUNIT_ASSERT(strcmp(str1->String(), "abc abc abc") == 0);
delete str1;
+ NextSubTest();
+ str1 = new BString("abc abc abc");
+ str1->ReplaceAll("abc", NULL);
+ CPPUNIT_ASSERT(strcmp(str1->String(), " ") == 0);
+ delete str1;
+
NextSubTest();
str1 = new BString("she sells sea shells on the seashore");
str1->ReplaceAll("tex", "the");
@@ -244,6 +263,13 @@ StringReplaceTest::PerformTest(void)
"she sells sea shells on the seashore") == 0);
delete str1;
+ NextSubTest();
+ str1 = new BString("she sells SeA shells on the seashore");
+ str1->IReplaceFirst("sea ", NULL);
+ CPPUNIT_ASSERT(strcmp(str1->String(),
+ "she sells shells on the seashore") == 0);
+ delete str1;
+
// &IReplaceLast(const char*, const char*)
#ifndef TEST_R5
NextSubTest();
@@ -260,6 +286,13 @@ StringReplaceTest::PerformTest(void)
"she sells sea shells on the seashore") == 0);
delete str1;
+ NextSubTest();
+ str1 = new BString("she sells sea shells on the SEashore");
+ str1->IReplaceLast("sea", NULL);
+ CPPUNIT_ASSERT(strcmp(str1->String(),
+ "she sells sea shells on the shore") == 0);
+ delete str1;
+
// &IReplaceAll(const char*, const char*, int32)
NextSubTest();
str1 = new BString("abc ABc aBc");
@@ -282,6 +315,13 @@ StringReplaceTest::PerformTest(void)
"she sells SeA shells on the theshore") == 0);
delete str1;
+ NextSubTest();
+ str1 = new BString("abc ABc aBc");
+ str1->IReplaceAll("ab", NULL);
+ CPPUNIT_ASSERT(strcmp(str1->String(),
+ "c c c") == 0);
+ delete str1;
+
// ReplaceSet(const char*, char)
NextSubTest();
str1 = new BString("abc abc abc");
############################################################################
Revision: hrev52348
Commit: f436972c145055b1a810c597a35e394cf73ef2d2
URL: https://git.haiku-os.org/haiku/commit/?id=f436972c1450
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Sun Sep 16 17:55:06 2018 UTC
Committer: waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Sun Sep 16 17:57:02 2018 UTC
Ticket: https://dev.haiku-os.org/ticket/8552
BString: Treat NULL passed as replaceWith as an empty string.
Fixes the tests added in the previous commit, and also #8552.
Change-Id: Idf9459474bc66054f94cf66065ed6fcf9c60cece
Reviewed-on: https://review.haiku-os.org/572
Reviewed-by: waddlesplash <waddlesplash@xxxxxxxxx>
----------------------------------------------------------------------------
diff --git a/src/kits/support/String.cpp b/src/kits/support/String.cpp
index 9643e3c5ea..d153b1fcb1 100644
--- a/src/kits/support/String.cpp
+++ b/src/kits/support/String.cpp
@@ -1545,7 +1545,7 @@ BString::Replace(char replaceThis, char withThis, int32
maxReplaceCount,
BString&
BString::ReplaceFirst(const char* replaceThis, const char* withThis)
{
- if (!replaceThis || !withThis || FindFirst(replaceThis) < 0)
+ if (replaceThis == NULL || FindFirst(replaceThis) < 0)
return *this;
if (_MakeWritable() != B_OK)
@@ -1558,14 +1558,16 @@ BString::ReplaceFirst(const char* replaceThis, const
char* withThis)
BString&
BString::ReplaceLast(const char* replaceThis, const char* withThis)
{
- if (!replaceThis || !withThis)
+ if (replaceThis == NULL)
return *this;
+ if (withThis == NULL)
+ withThis = "";
int32 replaceThisLength = strlen(replaceThis);
int32 pos = _FindBefore(replaceThis, Length(), replaceThisLength);
if (pos >= 0) {
- int32 withThisLength = strlen(withThis);
+ int32 withThisLength = strlen(withThis);
int32 difference = withThisLength - replaceThisLength;
if (difference > 0) {
@@ -1589,7 +1591,7 @@ BString&
BString::ReplaceAll(const char* replaceThis, const char* withThis,
int32 fromOffset)
{
- if (!replaceThis || !withThis || FindFirst(replaceThis) < 0)
+ if (replaceThis == NULL || FindFirst(replaceThis) < 0)
return *this;
if (_MakeWritable() != B_OK)
@@ -1604,7 +1606,7 @@ BString&
BString::Replace(const char* replaceThis, const char* withThis,
int32 maxReplaceCount, int32 fromOffset)
{
- if (!replaceThis || !withThis || maxReplaceCount <= 0
+ if (replaceThis == NULL || maxReplaceCount <= 0
|| FindFirst(replaceThis) < 0)
return *this;
@@ -1696,7 +1698,7 @@ BString::IReplace(char replaceThis, char withThis, int32
maxReplaceCount,
BString&
BString::IReplaceFirst(const char* replaceThis, const char* withThis)
{
- if (!replaceThis || !withThis || IFindFirst(replaceThis) < 0)
+ if (replaceThis == NULL || IFindFirst(replaceThis) < 0)
return *this;
if (_MakeWritable() != B_OK)
@@ -1708,8 +1710,10 @@ BString::IReplaceFirst(const char* replaceThis, const
char* withThis)
BString&
BString::IReplaceLast(const char* replaceThis, const char* withThis)
{
- if (!replaceThis || !withThis)
+ if (replaceThis == NULL)
return *this;
+ if (withThis == NULL)
+ withThis = "";
int32 replaceThisLength = strlen(replaceThis);
int32 pos = _IFindBefore(replaceThis, Length(), replaceThisLength);
@@ -1739,7 +1743,7 @@ BString&
BString::IReplaceAll(const char* replaceThis, const char* withThis,
int32 fromOffset)
{
- if (!replaceThis || !withThis || IFindFirst(replaceThis) < 0)
+ if (replaceThis == NULL || IFindFirst(replaceThis) < 0)
return *this;
if (_MakeWritable() != B_OK)
@@ -1754,7 +1758,7 @@ BString&
BString::IReplace(const char* replaceThis, const char* withThis,
int32 maxReplaceCount, int32 fromOffset)
{
- if (!replaceThis || !withThis || maxReplaceCount <= 0
+ if (replaceThis == NULL || maxReplaceCount <= 0
|| FindFirst(replaceThis) < 0)
return *this;
@@ -2634,7 +2638,7 @@ BString::_DoReplace(const char* findThis, const char*
replaceWith,
TFindMethod findMethod = ignoreCase
? &BString::_IFindAfter : &BString::_FindAfter;
- if (!replaceWith)
+ if (replaceWith == NULL)
replaceWith = "";
int32 replaceLen = strlen(replaceWith);