Loading base/include/android-base/strings.h +3 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,9 @@ bool StartsWithIgnoreCase(const std::string& s, const char* prefix); bool EndsWith(const std::string& s, const char* suffix); bool EndsWithIgnoreCase(const std::string& s, const char* suffix); // Tests whether 'lhs' equals 'rhs', ignoring case. bool EqualsIgnoreCase(const std::string& lhs, const std::string& rhs); } // namespace base } // namespace android Loading base/strings.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -112,5 +112,9 @@ bool EndsWithIgnoreCase(const std::string& s, const char* suffix) { return EndsWith(s, suffix, false); } bool EqualsIgnoreCase(const std::string& lhs, const std::string& rhs) { return strcasecmp(lhs.c_str(), rhs.c_str()) == 0; } } // namespace base } // namespace android base/strings_test.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -244,3 +244,10 @@ TEST(strings, EndsWithIgnoreCase_contains_prefix) { ASSERT_FALSE(android::base::EndsWithIgnoreCase("foobar", "OBA")); ASSERT_FALSE(android::base::EndsWithIgnoreCase("foobar", "FOO")); } TEST(strings, EqualsIgnoreCase) { ASSERT_TRUE(android::base::EqualsIgnoreCase("foo", "FOO")); ASSERT_TRUE(android::base::EqualsIgnoreCase("FOO", "foo")); ASSERT_FALSE(android::base::EqualsIgnoreCase("foo", "bar")); ASSERT_FALSE(android::base::EqualsIgnoreCase("foo", "fool")); } Loading
base/include/android-base/strings.h +3 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,9 @@ bool StartsWithIgnoreCase(const std::string& s, const char* prefix); bool EndsWith(const std::string& s, const char* suffix); bool EndsWithIgnoreCase(const std::string& s, const char* suffix); // Tests whether 'lhs' equals 'rhs', ignoring case. bool EqualsIgnoreCase(const std::string& lhs, const std::string& rhs); } // namespace base } // namespace android Loading
base/strings.cpp +4 −0 Original line number Diff line number Diff line Loading @@ -112,5 +112,9 @@ bool EndsWithIgnoreCase(const std::string& s, const char* suffix) { return EndsWith(s, suffix, false); } bool EqualsIgnoreCase(const std::string& lhs, const std::string& rhs) { return strcasecmp(lhs.c_str(), rhs.c_str()) == 0; } } // namespace base } // namespace android
base/strings_test.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -244,3 +244,10 @@ TEST(strings, EndsWithIgnoreCase_contains_prefix) { ASSERT_FALSE(android::base::EndsWithIgnoreCase("foobar", "OBA")); ASSERT_FALSE(android::base::EndsWithIgnoreCase("foobar", "FOO")); } TEST(strings, EqualsIgnoreCase) { ASSERT_TRUE(android::base::EqualsIgnoreCase("foo", "FOO")); ASSERT_TRUE(android::base::EqualsIgnoreCase("FOO", "foo")); ASSERT_FALSE(android::base::EqualsIgnoreCase("foo", "bar")); ASSERT_FALSE(android::base::EqualsIgnoreCase("foo", "fool")); }