From 7e7b0497a7ddc9681b9ee5ce4a243feccedaf25c Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 21 Jan 2017 14:06:06 -0500 Subject: [PATCH] allow comparison between an EncodedString and a std::string --- src/core/EncodedString.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/core/EncodedString.h b/src/core/EncodedString.h index f57f8f7..fe9495d 100644 --- a/src/core/EncodedString.h +++ b/src/core/EncodedString.h @@ -3,6 +3,7 @@ #include "Encoding.h" #include +#include class EncodedString { @@ -53,6 +54,14 @@ public: { return m_data[index]; } + bool operator==(const std::string & s) const + { + return (m_size == s.size()) && (memcmp(m_data, &s[0], m_size) == 0); + } + bool operator!=(const std::string & s) const + { + return !(*this == s); + } protected: Encoding::Type m_encoding; @@ -60,4 +69,13 @@ protected: size_t m_size; }; +static inline bool operator==(const std::string & ss, const EncodedString & es) +{ + return es == ss; +} +static inline bool operator!=(const std::string & ss, const EncodedString & es) +{ + return es != ss; +} + #endif