diff options
author | Attila Molnar <attilamolnar@hush.com> | 2013-12-19 17:30:22 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-01-04 19:38:20 +0100 |
commit | b5bc73e31026ee2087f0ceb5c7d9f99bf3c288a6 (patch) | |
tree | c19a15d127619fe9673d004b81fb4422276d778f /src/hashcomp.cpp | |
parent | 428e8f4f693192a527065e5488bbc7fceb938b6f (diff) |
Add functor that does strict weak ordering based on national_case_insensitive_map
Diffstat (limited to 'src/hashcomp.cpp')
-rw-r--r-- | src/hashcomp.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 4eb416406..f1d0f0678 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -170,6 +170,25 @@ bool irc::StrHashComp::operator()(const std::string& s1, const std::string& s2) return (national_case_insensitive_map[*n1] == national_case_insensitive_map[*n2]); } +bool irc::insensitive_swo::operator()(const std::string& a, const std::string& b) const +{ + const unsigned char* charmap = national_case_insensitive_map; + std::string::size_type asize = a.size(); + std::string::size_type bsize = b.size(); + std::string::size_type maxsize = std::min(asize, bsize); + + for (std::string::size_type i = 0; i < maxsize; i++) + { + unsigned char A = charmap[(unsigned char)a[i]]; + unsigned char B = charmap[(unsigned char)b[i]]; + if (A > B) + return false; + else if (A < B) + return true; + } + return (asize < bsize); +} + size_t irc::insensitive::operator()(const std::string &s) const { /* XXX: NO DATA COPIES! :) |