mirror of
https://github.com/anope/anope.git
synced 2026-07-08 14:03:13 +02:00
Fixed looking up users to use case insensitivity
This commit is contained in:
@@ -153,6 +153,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.
|
||||
*/
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
+19
-10
@@ -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);
|
||||
|
||||
+1
-1
@@ -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>
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user