diff options
-rw-r--r-- | include/anope.h | 5 | ||||
-rw-r--r-- | include/bots.h | 2 | ||||
-rw-r--r-- | include/hashcomp.h | 23 | ||||
-rw-r--r-- | include/patricia.h | 29 | ||||
-rw-r--r-- | include/users.h | 2 | ||||
-rw-r--r-- | src/bots.cpp | 2 | ||||
-rw-r--r-- | src/hashcomp.cpp | 15 | ||||
-rw-r--r-- | src/users.cpp | 2 |
8 files changed, 66 insertions, 14 deletions
diff --git a/include/anope.h b/include/anope.h index 7b9e9ccd1..3020feb54 100644 --- a/include/anope.h +++ b/include/anope.h @@ -154,6 +154,11 @@ namespace Anope inline size_type length() const { return this->_string.length(); } /** + * Add a char to the end of the string. + */ + inline void push_back(char c) { return this->_string.push_back(c); } + + /** * Resizes the string content to n characters. */ inline void resize(size_type n) { return this->_string.resize(n); } diff --git a/include/bots.h b/include/bots.h index bbd40a236..224f4b799 100644 --- a/include/bots.h +++ b/include/bots.h @@ -12,7 +12,7 @@ class BotInfo; -extern CoreExport patricia_tree<BotInfo *, std::equal_to<ci::string> > BotListByNick; +extern CoreExport patricia_tree<BotInfo *, ci::ci_char_traits> BotListByNick; extern CoreExport patricia_tree<BotInfo *> BotListByUID; /** Flags settable on a bot diff --git a/include/hashcomp.h b/include/hashcomp.h index 8fb76bcd0..b99b97aa4 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -162,6 +162,12 @@ namespace irc * @return Pointer to the first occurance of c in s1 */ static const char *find(const char *s1, int n, char c); + + /** Convert a char to lowercase + * @param c1 The character to convert + * @return The lowercase version of the char + */ + static const char chartolower(char c1); }; /** This typedef declares irc::string based upon irc_char_traits. @@ -233,6 +239,12 @@ namespace ci * @return Pointer to the first occurance of c in s1 */ static const char *find(const char *s1, int n, char c); + + /** Convert a char to lowercase + * @param c1 The character to convert + * @return The lowercase version of the char + */ + static const char chartolower(char c1); }; /** This typedef declares ci::string based upon ci_char_traits. @@ -259,6 +271,17 @@ namespace ci namespace std { + /** The std_char_traits class is used for normal comparison of strings. + */ + struct CoreExport std_char_traits : char_traits<char> + { + /** Convert a char to lowercase + * @param c1 The character to convert + * @return The lowercase version of the char + */ + static const char chartolower(char c1); + }; + /** An overload for std::equal_to<ci::string> that uses Anope::string, passed for the fourth temmplate * argument for unordered_map */ diff --git a/include/patricia.h b/include/patricia.h index fc28f4195..a7c1d08f0 100644 --- a/include/patricia.h +++ b/include/patricia.h @@ -13,10 +13,10 @@ template<typename Data> struct patricia_elem Data data; }; -template<typename Data, typename Compare = std::equal_to<Anope::string> > +template<typename Data, typename char_traits = std::std_char_traits> class patricia_tree { - Compare comp; + typedef std::basic_string<char, char_traits, std::allocator<char> > String; patricia_elem<Data> *root; std::list<Data> list; @@ -49,8 +49,12 @@ class patricia_tree inline size_t size() const { return this->list.size(); } inline bool empty() const { return this->list.empty(); } - Data find(const Anope::string &key) + Data find(const Anope::string &ukey) { + Anope::string key; + for (size_t i = 0, j = ukey.length(); i < j; ++i) + key.push_back(char_traits::chartolower(ukey[i])); + size_t keylen = key.length(); patricia_elem<Data> *prev = NULL, *cur = this->root; bool bitval; @@ -66,16 +70,17 @@ class patricia_tree cur = bitval ? cur->one : cur->zero; } - if (cur && comp(cur->key, key)) + if (cur && String(cur->key.c_str()).compare(key.c_str()) == 0) return cur->data; return NULL; } - void insert(const Anope::string &key, Data data) + void insert(const Anope::string &ukey, Data data) { - if (key.empty() || data == NULL) - throw CoreExport; + Anope::string key; + for (size_t i = 0, j = ukey.length(); i < j; ++i) + key.push_back(char_traits::chartolower(ukey[i])); size_t keylen = key.length(); patricia_elem<Data> *prev = NULL, *cur = this->root; @@ -92,7 +97,7 @@ class patricia_tree cur = bitval ? cur->one : cur->zero; } - if (cur && comp(cur->key, key)) + if (cur && String(cur->key.c_str()).compare(key.c_str()) == 0) return; patricia_elem<Data> *newelem = new patricia_elem<Data>(); @@ -144,8 +149,12 @@ class patricia_tree newelem->node = this->list.begin(); } - Data erase(const Anope::string &key) + Data erase(const Anope::string &ukey) { + Anope::string key; + for (size_t i = 0, j = ukey.length(); i < j; ++i) + key.push_back(char_traits::chartolower(ukey[i])); + size_t keylen = key.length(); patricia_elem<Data> *prev = NULL, *cur = this->root; bool bitval; @@ -161,7 +170,7 @@ class patricia_tree cur = bitval ? cur->one : cur->zero; } - if (!cur || comp(cur->key, key) == false) + if (!cur || String(cur->key.c_str()).compare(key.c_str())) return NULL; patricia_elem<Data> *other = (bitval ? prev->zero : prev->one); diff --git a/include/users.h b/include/users.h index b6e8ec612..26ee5f33e 100644 --- a/include/users.h +++ b/include/users.h @@ -8,7 +8,7 @@ #ifndef USERS_H #define USERS_H -extern CoreExport patricia_tree<User *, std::equal_to<ci::string> > UserListByNick; +extern CoreExport patricia_tree<User *, ci::ci_char_traits> UserListByNick; extern CoreExport patricia_tree<User *> UserListByUID; class CoreExport ChannelStatus : public Flags<ChannelModeName, CMODE_END * 2> diff --git a/src/bots.cpp b/src/bots.cpp index 09742acff..098404ceb 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -9,7 +9,7 @@ #include "modules.h" #include "commands.h" -patricia_tree<BotInfo *, std::equal_to<ci::string> > BotListByNick; +patricia_tree<BotInfo *, ci::ci_char_traits> BotListByNick; patricia_tree<BotInfo *> BotListByUID; BotInfo *BotServ = NULL; diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 5f65738ea..d50fca3c0 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -87,6 +87,11 @@ const char *irc::irc_char_traits::find(const char *s1, int n, char c) return n >= 0 ? s1 : NULL; } +const char irc::irc_char_traits::chartolower(char c1) +{ + return rfc_case_insensitive_map[static_cast<unsigned char>(c1)]; +} + /* VS 2008 specific function */ bool irc::hash::operator()(const Anope::string &s1, const Anope::string &s2) const { @@ -153,6 +158,11 @@ const char *ci::ci_char_traits::find(const char *s1, int n, char c) return n >= 0 ? s1 : NULL; } +const char ci::ci_char_traits::chartolower(char c1) +{ + return ascii_case_insensitive_map[static_cast<unsigned char>(c1)]; +} + /* VS 2008 specific function */ bool ci::hash::operator()(const Anope::string &s1, const Anope::string &s2) const { @@ -178,6 +188,11 @@ size_t ci::hash::operator()(const Anope::string &s) const return operator()(s.ci_str()); } +const char std::std_char_traits::chartolower(char c1) +{ + return c1; +} + /** Compare two Anope::strings as ci::strings * @param s1 The first string * @param s2 The second string diff --git a/src/users.cpp b/src/users.cpp index 58d931789..f6c0983ef 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -12,7 +12,7 @@ #include "services.h" #include "modules.h" -patricia_tree<User *, std::equal_to<ci::string> > UserListByNick; +patricia_tree<User *, ci::ci_char_traits> UserListByNick; patricia_tree<User *> UserListByUID; int32 opcnt = 0; |