diff options
author | Adam <Adam@anope.org> | 2010-11-30 17:25:42 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-12-12 19:37:03 -0500 |
commit | a507816701d136a1c22d2f6779d811840d61577c (patch) | |
tree | 37e397d8e6d6f04685287b7ec3aa7d0662460da4 /include | |
parent | c41c82857464c34c61e6f2cf1939cea866f7d49a (diff) |
Fixed looking up users to use case insensitivity
Diffstat (limited to 'include')
-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 |
5 files changed, 49 insertions, 12 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> |