diff options
author | Attila Molnar <attilamolnar@hush.com> | 2016-08-22 16:49:18 +0200 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2016-08-22 16:49:18 +0200 |
commit | ecef36edcab5219ce1a759eb0d2d24e061b4e886 (patch) | |
tree | d3bfd54bc9b95a564b4261563bd39a784e530e81 | |
parent | 90ea1b01b78a94486b8142808c06aacff543ca64 (diff) |
Create irc::equals() from StrHashComp
Make StrHashComp a wrapper around it
-rw-r--r-- | include/hashcomp.h | 16 | ||||
-rw-r--r-- | src/hashcomp.cpp | 2 |
2 files changed, 15 insertions, 3 deletions
diff --git a/include/hashcomp.h b/include/hashcomp.h index 168ecb289..aa204ace6 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -98,15 +98,27 @@ template<typename T> const T& SearchAndReplace(T& text, const T& pattern, const namespace irc { + /** Check if two IRC object (e.g. nick or channel) names are equal. + * This function uses national_case_insensitive_map to determine equality, which, by default does comparison + * according to RFC 1459, treating certain otherwise non-identical characters as identical. + * @param s1 First string to compare + * @param s2 Second string to compare + * @return True if the two names are equal, false otherwise + */ + CoreExport bool equals(const std::string& s1, const std::string& s2); + /** This class returns true if two strings match. * Case sensitivity is ignored, and the RFC 'character set' * is adhered to */ - struct CoreExport StrHashComp + struct StrHashComp { /** The operator () does the actual comparison in hash_map */ - bool operator()(const std::string& s1, const std::string& s2) const; + bool operator()(const std::string& s1, const std::string& s2) const + { + return equals(s1, s2); + } }; struct insensitive diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 1bbc35d1f..2c7dca5b1 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -151,7 +151,7 @@ unsigned const char rfc_case_sensitive_map[256] = { 250, 251, 252, 253, 254, 255, // 250-255 }; -bool irc::StrHashComp::operator()(const std::string& s1, const std::string& s2) const +bool irc::equals(const std::string& s1, const std::string& s2) { const unsigned char* n1 = (const unsigned char*)s1.c_str(); const unsigned char* n2 = (const unsigned char*)s2.c_str(); |