summaryrefslogtreecommitdiff
path: root/src/hashcomp.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2014-12-29 17:26:20 -0500
committerAdam <Adam@anope.org>2014-12-29 17:26:20 -0500
commit8ab1c71d7dc7a0d47e5711dc72e3fc9c3ee850bb (patch)
treed65f46a60e49d51ee1f0192de22c35e3cdd322c9 /src/hashcomp.cpp
parented920366d69801bab7fc276fa24296b7f1264ff2 (diff)
Allow configuring casemaps
Diffstat (limited to 'src/hashcomp.cpp')
-rw-r--r--src/hashcomp.cpp38
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;
}