summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2015-06-25 08:52:08 +0200
committerStephan Bergmann <sbergman@redhat.com>2015-06-25 08:52:37 +0200
commitf7a7a9dd84d1cd8b49d59e1fb1853ea7e9f40edf (patch)
tree6f4d91d99d9cfef5035a4a1e5b42097e0df119f6 /sal
parent0e2db2dd3413d760afaa4cfab4c7c224222b949a (diff)
Do not forget to actually set newStr to an empty string
Change-Id: I745b09d8a248f08afdd3387f4cfcf69d71ec3c39
Diffstat (limited to 'sal')
-rw-r--r--sal/qa/rtl/strings/test_strings_replace.cxx19
-rw-r--r--sal/rtl/ustring.cxx6
2 files changed, 22 insertions, 3 deletions
diff --git a/sal/qa/rtl/strings/test_strings_replace.cxx b/sal/qa/rtl/strings/test_strings_replace.cxx
index 0d47c3e6f4c5..02054c1d8028 100644
--- a/sal/qa/rtl/strings/test_strings_replace.cxx
+++ b/sal/qa/rtl/strings/test_strings_replace.cxx
@@ -20,6 +20,7 @@
namespace {
+OUString s_empty;
OUString s_bar("bar");
OUString s_bars("bars");
OUString s_foo("foo");
@@ -176,6 +177,9 @@ void Test::ustringReplaceFirstAsciiL() {
rtl::OUString("foobarfoo").replaceFirst("bar", s_other, &n));
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n);
}
+
+ CPPUNIT_ASSERT_EQUAL(
+ rtl::OUString(), rtl::OUString("xa").replaceFirst("xa", s_empty));
}
void Test::ustringReplaceFirstToAsciiL() {
@@ -210,6 +214,9 @@ void Test::ustringReplaceFirstToAsciiL() {
rtl::OUString("foobarfoo").replaceFirst(s_bar, "other", &n));
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n);
}
+
+ CPPUNIT_ASSERT_EQUAL(
+ rtl::OUString(), rtl::OUString("xa").replaceFirst(s_xa, ""));
}
void Test::ustringReplaceFirstAsciiLAsciiL() {
@@ -249,6 +256,9 @@ void Test::ustringReplaceFirstAsciiLAsciiL() {
replaceFirst("bar", "other", &n)));
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n);
}
+
+ CPPUNIT_ASSERT_EQUAL(
+ rtl::OUString(), rtl::OUString("xa").replaceFirst("xa", ""));
}
void Test::ustringReplaceAll() {
@@ -277,6 +287,9 @@ void Test::ustringReplaceAllAsciiL() {
CPPUNIT_ASSERT_EQUAL(
rtl::OUString("xxa"),
rtl::OUString("xaa").replaceAll("xa", s_xx));
+
+ CPPUNIT_ASSERT_EQUAL(
+ rtl::OUString(), rtl::OUString("xa").replaceAll("xa", s_empty));
}
void Test::ustringReplaceAllToAsciiL() {
@@ -291,6 +304,9 @@ void Test::ustringReplaceAllToAsciiL() {
CPPUNIT_ASSERT_EQUAL(
rtl::OUString("xxa"),
rtl::OUString("xaa").replaceAll(s_xa, "xx"));
+
+ CPPUNIT_ASSERT_EQUAL(
+ rtl::OUString(), rtl::OUString("xa").replaceAll(s_xa, ""));
}
void Test::ustringReplaceAllAsciiLAsciiL() {
@@ -308,6 +324,9 @@ void Test::ustringReplaceAllAsciiLAsciiL() {
rtl::OUString("xxa"),
(rtl::OUString("xaa").
replaceAll("xa", "xx")));
+
+ CPPUNIT_ASSERT_EQUAL(
+ rtl::OUString(), rtl::OUString("xa").replaceAll("xa", ""));
}
}
diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx
index 827077468fd5..de733e86be0d 100644
--- a/sal/rtl/ustring.cxx
+++ b/sal/rtl/ustring.cxx
@@ -1154,8 +1154,8 @@ void rtl_uString_newReplaceFirstAsciiL(
}
sal_Int32 n = str->length - fromLength + to->length;
rtl_uString_acquire(str); // in case *newStr == str
+ rtl_uString_new_WithLength(newStr, n);
if (n != 0) {
- rtl_uString_new_WithLength(newStr, n);
(*newStr)->length = n;
assert(i >= 0 && i < str->length);
memcpy(
@@ -1196,8 +1196,8 @@ void rtl_uString_newReplaceFirstToAsciiL(
}
sal_Int32 n = str->length - from->length + toLength;
rtl_uString_acquire(str); // in case *newStr == str
+ rtl_uString_new_WithLength(newStr, n);
if (n != 0) {
- rtl_uString_new_WithLength(newStr, n);
(*newStr)->length = n;
assert(i >= 0 && i < str->length);
memcpy(
@@ -1240,8 +1240,8 @@ void rtl_uString_newReplaceFirstAsciiLAsciiL(
}
sal_Int32 n = str->length - fromLength + toLength;
rtl_uString_acquire(str); // in case *newStr == str
+ rtl_uString_new_WithLength(newStr, n);
if (n != 0) {
- rtl_uString_new_WithLength(newStr, n);
(*newStr)->length = n;
assert(i >= 0 && i < str->length);
memcpy(