Kaydet (Commit) f7a7a9dd authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Do not forget to actually set newStr to an empty string

Change-Id: I745b09d8a248f08afdd3387f4cfcf69d71ec3c39
üst 0e2db2dd
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
namespace { namespace {
OUString s_empty;
OUString s_bar("bar"); OUString s_bar("bar");
OUString s_bars("bars"); OUString s_bars("bars");
OUString s_foo("foo"); OUString s_foo("foo");
...@@ -176,6 +177,9 @@ void Test::ustringReplaceFirstAsciiL() { ...@@ -176,6 +177,9 @@ void Test::ustringReplaceFirstAsciiL() {
rtl::OUString("foobarfoo").replaceFirst("bar", s_other, &n)); rtl::OUString("foobarfoo").replaceFirst("bar", s_other, &n));
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n); CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n);
} }
CPPUNIT_ASSERT_EQUAL(
rtl::OUString(), rtl::OUString("xa").replaceFirst("xa", s_empty));
} }
void Test::ustringReplaceFirstToAsciiL() { void Test::ustringReplaceFirstToAsciiL() {
...@@ -210,6 +214,9 @@ void Test::ustringReplaceFirstToAsciiL() { ...@@ -210,6 +214,9 @@ void Test::ustringReplaceFirstToAsciiL() {
rtl::OUString("foobarfoo").replaceFirst(s_bar, "other", &n)); rtl::OUString("foobarfoo").replaceFirst(s_bar, "other", &n));
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n); CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n);
} }
CPPUNIT_ASSERT_EQUAL(
rtl::OUString(), rtl::OUString("xa").replaceFirst(s_xa, ""));
} }
void Test::ustringReplaceFirstAsciiLAsciiL() { void Test::ustringReplaceFirstAsciiLAsciiL() {
...@@ -249,6 +256,9 @@ void Test::ustringReplaceFirstAsciiLAsciiL() { ...@@ -249,6 +256,9 @@ void Test::ustringReplaceFirstAsciiLAsciiL() {
replaceFirst("bar", "other", &n))); replaceFirst("bar", "other", &n)));
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n); CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n);
} }
CPPUNIT_ASSERT_EQUAL(
rtl::OUString(), rtl::OUString("xa").replaceFirst("xa", ""));
} }
void Test::ustringReplaceAll() { void Test::ustringReplaceAll() {
...@@ -277,6 +287,9 @@ void Test::ustringReplaceAllAsciiL() { ...@@ -277,6 +287,9 @@ void Test::ustringReplaceAllAsciiL() {
CPPUNIT_ASSERT_EQUAL( CPPUNIT_ASSERT_EQUAL(
rtl::OUString("xxa"), rtl::OUString("xxa"),
rtl::OUString("xaa").replaceAll("xa", s_xx)); rtl::OUString("xaa").replaceAll("xa", s_xx));
CPPUNIT_ASSERT_EQUAL(
rtl::OUString(), rtl::OUString("xa").replaceAll("xa", s_empty));
} }
void Test::ustringReplaceAllToAsciiL() { void Test::ustringReplaceAllToAsciiL() {
...@@ -291,6 +304,9 @@ void Test::ustringReplaceAllToAsciiL() { ...@@ -291,6 +304,9 @@ void Test::ustringReplaceAllToAsciiL() {
CPPUNIT_ASSERT_EQUAL( CPPUNIT_ASSERT_EQUAL(
rtl::OUString("xxa"), rtl::OUString("xxa"),
rtl::OUString("xaa").replaceAll(s_xa, "xx")); rtl::OUString("xaa").replaceAll(s_xa, "xx"));
CPPUNIT_ASSERT_EQUAL(
rtl::OUString(), rtl::OUString("xa").replaceAll(s_xa, ""));
} }
void Test::ustringReplaceAllAsciiLAsciiL() { void Test::ustringReplaceAllAsciiLAsciiL() {
...@@ -308,6 +324,9 @@ void Test::ustringReplaceAllAsciiLAsciiL() { ...@@ -308,6 +324,9 @@ void Test::ustringReplaceAllAsciiLAsciiL() {
rtl::OUString("xxa"), rtl::OUString("xxa"),
(rtl::OUString("xaa"). (rtl::OUString("xaa").
replaceAll("xa", "xx"))); replaceAll("xa", "xx")));
CPPUNIT_ASSERT_EQUAL(
rtl::OUString(), rtl::OUString("xa").replaceAll("xa", ""));
} }
} }
......
...@@ -1154,8 +1154,8 @@ void rtl_uString_newReplaceFirstAsciiL( ...@@ -1154,8 +1154,8 @@ void rtl_uString_newReplaceFirstAsciiL(
} }
sal_Int32 n = str->length - fromLength + to->length; sal_Int32 n = str->length - fromLength + to->length;
rtl_uString_acquire(str); // in case *newStr == str rtl_uString_acquire(str); // in case *newStr == str
if (n != 0) {
rtl_uString_new_WithLength(newStr, n); rtl_uString_new_WithLength(newStr, n);
if (n != 0) {
(*newStr)->length = n; (*newStr)->length = n;
assert(i >= 0 && i < str->length); assert(i >= 0 && i < str->length);
memcpy( memcpy(
...@@ -1196,8 +1196,8 @@ void rtl_uString_newReplaceFirstToAsciiL( ...@@ -1196,8 +1196,8 @@ void rtl_uString_newReplaceFirstToAsciiL(
} }
sal_Int32 n = str->length - from->length + toLength; sal_Int32 n = str->length - from->length + toLength;
rtl_uString_acquire(str); // in case *newStr == str rtl_uString_acquire(str); // in case *newStr == str
if (n != 0) {
rtl_uString_new_WithLength(newStr, n); rtl_uString_new_WithLength(newStr, n);
if (n != 0) {
(*newStr)->length = n; (*newStr)->length = n;
assert(i >= 0 && i < str->length); assert(i >= 0 && i < str->length);
memcpy( memcpy(
...@@ -1240,8 +1240,8 @@ void rtl_uString_newReplaceFirstAsciiLAsciiL( ...@@ -1240,8 +1240,8 @@ void rtl_uString_newReplaceFirstAsciiLAsciiL(
} }
sal_Int32 n = str->length - fromLength + toLength; sal_Int32 n = str->length - fromLength + toLength;
rtl_uString_acquire(str); // in case *newStr == str rtl_uString_acquire(str); // in case *newStr == str
if (n != 0) {
rtl_uString_new_WithLength(newStr, n); rtl_uString_new_WithLength(newStr, n);
if (n != 0) {
(*newStr)->length = n; (*newStr)->length = n;
assert(i >= 0 && i < str->length); assert(i >= 0 && i < str->length);
memcpy( memcpy(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment