diff options
Diffstat (limited to 'src/hashcomp.cpp')
-rw-r--r-- | src/hashcomp.cpp | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 62bcc404f..e17ae6176 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -10,32 +10,22 @@ #include "services.h" #include "hashcomp.h" #include "anope.h" - -/* Case map in use by Anope */ -std::locale Anope::casemap = std::locale(std::locale(), new Anope::ascii_ctype<char>()); -/* Cache of the above case map, forced upper */ -static unsigned char case_map_upper[256], case_map_lower[256]; - -/* called whenever Anope::casemap is modified to rebuild the casemap cache */ -void Anope::CaseMapRebuild() -{ - const std::ctype<char> &ct = std::use_facet<std::ctype<char> >(Anope::casemap); - - for (unsigned i = 0; i < sizeof(case_map_upper); ++i) - { - case_map_upper[i] = ct.toupper(i); - case_map_lower[i] = ct.tolower(i); - } -} +#include "config.h" unsigned char Anope::tolower(unsigned char c) { - return case_map_lower[c]; + if (!Config || !Config->CaseMapLower[c]) + return std::tolower(c); + + return Config->CaseMapLower[c]; } unsigned char Anope::toupper(unsigned char c) { - return case_map_upper[c]; + if (!Config || !Config->CaseMapUpper[c]) + return std::toupper(c); + + return Config->CaseMapUpper[c]; } /* @@ -47,7 +37,7 @@ unsigned char Anope::toupper(unsigned char c) bool ci::ci_char_traits::eq(char c1st, char c2nd) { - return case_map_upper[static_cast<unsigned char>(c1st)] == case_map_upper[static_cast<unsigned char>(c2nd)]; + return Anope::toupper(c1st) == Anope::toupper(c2nd); } bool ci::ci_char_traits::ne(char c1st, char c2nd) @@ -57,15 +47,15 @@ bool ci::ci_char_traits::ne(char c1st, char c2nd) bool ci::ci_char_traits::lt(char c1st, char c2nd) { - return case_map_upper[static_cast<unsigned char>(c1st)] < case_map_upper[static_cast<unsigned char>(c2nd)]; + return Anope::toupper(c1st) < Anope::toupper(c2nd); } int ci::ci_char_traits::compare(const char *str1, const char *str2, size_t n) { for (unsigned i = 0; i < n; ++i) { - unsigned char c1 = case_map_upper[static_cast<unsigned char>(*str1)], - c2 = case_map_upper[static_cast<unsigned char>(*str2)]; + unsigned char c1 = Anope::toupper(*str1), + c2 = Anope::toupper(*str2); if (c1 > c2) return 1; @@ -82,7 +72,7 @@ int ci::ci_char_traits::compare(const char *str1, const char *str2, size_t n) const char *ci::ci_char_traits::find(const char *s1, int n, char c) { - while (n-- > 0 && case_map_upper[static_cast<unsigned char>(*s1)] != case_map_upper[static_cast<unsigned char>(c)]) + while (n-- > 0 && Anope::toupper(*s1) != Anope::toupper(c)) ++s1; return n >= 0 ? s1 : NULL; } |