allow comparison between an EncodedString and a std::string

This commit is contained in:
Josh Holtrop 2017-01-21 14:06:06 -05:00
parent fce9f87265
commit 7e7b0497a7

View File

@ -3,6 +3,7 @@
#include "Encoding.h" #include "Encoding.h"
#include <stdint.h> #include <stdint.h>
#include <string.h>
class EncodedString class EncodedString
{ {
@ -53,6 +54,14 @@ public:
{ {
return m_data[index]; 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: protected:
Encoding::Type m_encoding; Encoding::Type m_encoding;
@ -60,4 +69,13 @@ protected:
size_t m_size; 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 #endif