Loading libutils/String8.cpp +5 −0 Original line number Original line Diff line number Diff line Loading @@ -393,6 +393,11 @@ ssize_t String8::find(const char* other, size_t start) const } } bool String8::removeAll(const char* other) { bool String8::removeAll(const char* other) { ALOG_ASSERT(other, "String8::removeAll() requires a non-NULL string"); if (*other == '\0') return true; ssize_t index = find(other); ssize_t index = find(other); if (index < 0) return false; if (index < 0) return false; Loading libutils/String8_test.cpp +18 −0 Original line number Original line Diff line number Diff line Loading @@ -114,3 +114,21 @@ TEST_F(String8Test, append) { EXPECT_EQ(NO_MEMORY, s.append("baz", SIZE_MAX)); EXPECT_EQ(NO_MEMORY, s.append("baz", SIZE_MAX)); EXPECT_STREQ("foobar", s); EXPECT_STREQ("foobar", s); } } TEST_F(String8Test, removeAll) { String8 s("Hello, world!"); // NULL input should cause an assertion failure and error message in logcat EXPECT_DEATH(s.removeAll(NULL), ""); // expect to return true and string content should remain unchanged EXPECT_TRUE(s.removeAll("")); EXPECT_STREQ("Hello, world!", s); // expect to return false EXPECT_FALSE(s.removeAll("x")); EXPECT_STREQ("Hello, world!", s); EXPECT_TRUE(s.removeAll("o")); EXPECT_STREQ("Hell, wrld!", s); } Loading
libutils/String8.cpp +5 −0 Original line number Original line Diff line number Diff line Loading @@ -393,6 +393,11 @@ ssize_t String8::find(const char* other, size_t start) const } } bool String8::removeAll(const char* other) { bool String8::removeAll(const char* other) { ALOG_ASSERT(other, "String8::removeAll() requires a non-NULL string"); if (*other == '\0') return true; ssize_t index = find(other); ssize_t index = find(other); if (index < 0) return false; if (index < 0) return false; Loading
libutils/String8_test.cpp +18 −0 Original line number Original line Diff line number Diff line Loading @@ -114,3 +114,21 @@ TEST_F(String8Test, append) { EXPECT_EQ(NO_MEMORY, s.append("baz", SIZE_MAX)); EXPECT_EQ(NO_MEMORY, s.append("baz", SIZE_MAX)); EXPECT_STREQ("foobar", s); EXPECT_STREQ("foobar", s); } } TEST_F(String8Test, removeAll) { String8 s("Hello, world!"); // NULL input should cause an assertion failure and error message in logcat EXPECT_DEATH(s.removeAll(NULL), ""); // expect to return true and string content should remain unchanged EXPECT_TRUE(s.removeAll("")); EXPECT_STREQ("Hello, world!", s); // expect to return false EXPECT_FALSE(s.removeAll("x")); EXPECT_STREQ("Hello, world!", s); EXPECT_TRUE(s.removeAll("o")); EXPECT_STREQ("Hell, wrld!", s); }