From c4ebf02bce968e4846a0be72dfa7b104f21f5166 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 27 Aug 2016 12:28:27 -0400 Subject: Optionally allow using Boost.Locale for hashcomp --- include/anope.h | 41 ++++++++++++++++++++++++----------------- include/channels.h | 2 +- include/config.h | 1 + include/hashcomp.h | 14 ++++++++++++++ include/modules/chanserv.h | 2 +- include/modules/nickserv.h | 4 ++-- include/sysconf.h.cmake | 1 + include/users.h | 6 ++++-- 8 files changed, 48 insertions(+), 23 deletions(-) (limited to 'include') diff --git a/include/anope.h b/include/anope.h index d5e935891..c298d5d86 100644 --- a/include/anope.h +++ b/include/anope.h @@ -315,33 +315,40 @@ namespace Anope inline const string operator+(const char *_str, const string &str) { string tmp(_str); tmp += str; return tmp; } inline const string operator+(const std::string &_str, const string &str) { string tmp(_str); tmp += str; return tmp; } + struct hash + { + size_t operator()(const string &s) const; + }; + + struct compare + { + bool operator()(const string &s1, const string &s2) const; + }; + struct hash_ci { - inline size_t operator()(const string &s) const - { - return std::hash()(s.lower().str()); - } + size_t operator()(const string &s) const; }; - struct hash_cs + struct compare_ci { - inline size_t operator()(const string &s) const - { - return std::hash()(s.str()); - } + bool operator()(const string &s1, const string &s2) const; }; - struct compare + struct hash_locale { - inline bool operator()(const string &s1, const string &s2) const - { - return s1.equals_ci(s2); - } + size_t operator()(const string &s) const; + }; + + struct compare_locale + { + bool operator()(const string &s1, const string &s2) const; }; - template class map : public std::map { }; - template class multimap : public std::multimap { }; - template class hash_map : public std::unordered_map { }; + template using map = std::map; + template using multimap = std::multimap; + template using hash_map = std::unordered_map; + template using locale_hash_map = std::unordered_map; static const char *const compiled = __TIME__ " " __DATE__; diff --git a/include/channels.h b/include/channels.h index bfe2fc0d2..5888f84e3 100644 --- a/include/channels.h +++ b/include/channels.h @@ -24,7 +24,7 @@ #include "modes.h" #include "serialize.h" -typedef Anope::hash_map channel_map; +using channel_map = Anope::locale_hash_map; extern CoreExport channel_map ChannelList; diff --git a/include/config.h b/include/config.h index 6d73e03ad..7ca8caaf4 100644 --- a/include/config.h +++ b/include/config.h @@ -142,6 +142,7 @@ namespace Configuration std::vector Usermodes; std::vector Channelmodes; unsigned char CaseMapUpper[256] = { 0 }, CaseMapLower[256] = { 0 }; + std::locale *locale = nullptr; /* module configuration blocks */ std::map modules; diff --git a/include/hashcomp.h b/include/hashcomp.h index 470c054fd..d246bfd2b 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -152,3 +152,17 @@ inline bool operator!=(const std::string &leftval, const ci::string &rightval) return !(leftval.c_str() == rightval); } +namespace Anope { +namespace locale { + +#ifdef Boost_FOUND + +extern std::locale generate(const std::string &); +extern int compare(const std::string &, const std::string &); +extern long hash(const std::string &); + +#endif + +} +} + diff --git a/include/modules/chanserv.h b/include/modules/chanserv.h index 8029782bb..8c5687cc2 100644 --- a/include/modules/chanserv.h +++ b/include/modules/chanserv.h @@ -96,7 +96,7 @@ namespace ChanServ }; class Channel; - using registered_channel_map = Anope::hash_map; + using registered_channel_map = Anope::locale_hash_map; class Level : public Serialize::Object { diff --git a/include/modules/nickserv.h b/include/modules/nickserv.h index 047c2cf18..43e2a21ce 100644 --- a/include/modules/nickserv.h +++ b/include/modules/nickserv.h @@ -29,8 +29,8 @@ namespace NickServ class Account; class IdentifyRequestListener; - typedef Anope::hash_map nickalias_map; - typedef Anope::hash_map nickcore_map; + using nickalias_map = Anope::locale_hash_map; + using nickcore_map = Anope::locale_hash_map; class NickServService : public Service { diff --git a/include/sysconf.h.cmake b/include/sysconf.h.cmake index 8157bc0be..2d2ede9de 100644 --- a/include/sysconf.h.cmake +++ b/include/sysconf.h.cmake @@ -24,4 +24,5 @@ #cmakedefine DEFUMASK @DEFUMASK@ #cmakedefine HAVE_UMASK 1 #cmakedefine GETTEXT_FOUND 1 +#cmakedefine Boost_FOUND 1 diff --git a/include/users.h b/include/users.h index 046f41e8e..dacb7045e 100644 --- a/include/users.h +++ b/include/users.h @@ -27,9 +27,11 @@ #include "commands.h" #include "sockets.h" -typedef Anope::hash_map user_map; +using user_map = Anope::locale_hash_map; +using uid_map = std::unordered_map; -extern CoreExport user_map UserListByNick, UserListByUID; +extern CoreExport user_map UserListByNick; +extern CoreExport uid_map UserListByUID; extern CoreExport int OperCount; -- cgit