Fix asymmetry in hidl_string::operator==
Bug: 32456816
Test: libhidl-test
Change-Id: If13ef62a18b12cecb466b1e9701da2614ce75db8
diff --git a/include/hidl/HidlSupport.h b/include/hidl/HidlSupport.h
index 07eebeb..37c4431 100644
--- a/include/hidl/HidlSupport.h
+++ b/include/hidl/HidlSupport.h
@@ -76,14 +76,6 @@
status_t writeEmbeddedToParcel(
Parcel *parcel, size_t parentHandle, size_t parentOffset) const;
- inline bool operator==(const char *s) const {
- return strcmp(mBuffer, s) == 0;
- }
-
- inline bool operator!=(const char *s) const {
- return !(operator==(s));
- }
-
// offsetof(hidl_string, mBuffer) exposed since mBuffer is private.
static const size_t kOffsetOfBuffer;
@@ -99,6 +91,22 @@
void moveFrom(hidl_string &&);
};
+inline bool operator==(const hidl_string &hs, const char *s) {
+ return strcmp(hs.c_str(), s) == 0;
+}
+
+inline bool operator!=(const hidl_string &hs, const char *s) {
+ return !(hs == s);
+}
+
+inline bool operator==(const char *s, const hidl_string &hs) {
+ return strcmp(hs.c_str(), s) == 0;
+}
+
+inline bool operator!=(const char *s, const hidl_string &hs) {
+ return !(s == hs);
+}
+
////////////////////////////////////////////////////////////////////////////////
template<typename T>