Merge "bootable/recovery wants EqualsIgnoreCase."
am: 89e99f9e0e
Change-Id: Id7480e1a1fec5626a0bec22c2128dd419533e1aa
diff --git a/base/include/android-base/strings.h b/base/include/android-base/strings.h
index b8a9289..f5f5c11 100644
--- a/base/include/android-base/strings.h
+++ b/base/include/android-base/strings.h
@@ -64,6 +64,9 @@
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
diff --git a/base/strings.cpp b/base/strings.cpp
index 7a94ad7..46fe939 100644
--- a/base/strings.cpp
+++ b/base/strings.cpp
@@ -112,5 +112,9 @@
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
diff --git a/base/strings_test.cpp b/base/strings_test.cpp
index 5fb21dd..7a65a00 100644
--- a/base/strings_test.cpp
+++ b/base/strings_test.cpp
@@ -244,3 +244,10 @@
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"));
+}