diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/config.cpp | 24 | ||||
-rw-r--r-- | src/hashcomp.cpp | 78 | ||||
-rw-r--r-- | src/users.cpp | 5 |
4 files changed, 107 insertions, 4 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 373677fe7..007e3605a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,10 +49,10 @@ add_executable(${PROGRAM_NAME} ${SRC_SRCS}) set_target_properties(${PROGRAM_NAME} PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS} ${EXTRA_LDFLAGS}" ENABLE_EXPORTS ON INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON) # On Windows, also link Anope to the wsock32 and Ws2_32 library, as well as set the version if(WIN32) - target_link_libraries(${PROGRAM_NAME} wsock32 Ws2_32 ${LINK_LIBS} ${GETTEXT_LIBRARIES} ${WIN32_MEMORY}) + target_link_libraries(${PROGRAM_NAME} wsock32 Ws2_32 ${LINK_LIBS} ${GETTEXT_LIBRARIES} ${Boost_LIBRARIES} ${WIN32_MEMORY}) set_target_properties(${PROGRAM_NAME} PROPERTIES VERSION "${VERSION_DOTTED}") else() - target_link_libraries(${PROGRAM_NAME} ${LINK_LIBS} ${GETTEXT_LIBRARIES}) + target_link_libraries(${PROGRAM_NAME} ${LINK_LIBS} ${GETTEXT_LIBRARIES} ${Boost_LIBRARIES}) endif() # Building the Anope executable requires the version.h header to be generated add_dependencies(${PROGRAM_NAME} headers) diff --git a/src/config.cpp b/src/config.cpp index dbeb98f89..6d9cef04d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -178,6 +178,7 @@ Conf::Conf() : Block("") {"networkinfo", "userlen"}, {"networkinfo", "hostlen"}, {"networkinfo", "chanlen"}, + {"options", "casemap"}, }; for (unsigned i = 0; i < sizeof(noreload) / sizeof(noreload[0]); ++i) @@ -223,6 +224,27 @@ Conf::Conf() : Block("") this->TimeoutCheck = options->Get<time_t>("timeoutcheck"); this->NickChars = networkinfo->Get<Anope::string>("nick_chars"); + Anope::string locale = options->Get<Anope::string>("locale"); + Anope::string casemap = options->Get<Anope::string>("casemap"); + + if (locale.empty() == casemap.empty()) + throw ConfigException("One of options:locale and options:casemap must be set"); + + if (locale.empty()) + { + // load locale conf + File f(casemap + ".conf", false); + this->LoadConf(f); + } + else + { +#if Boost_FOUND + this->locale = new std::locale(Anope::locale::generate(locale.str())); +#else + throw ConfigException("Boost.Locale is not enabled, cannot use locale " + locale); +#endif + } + for (int i = 0; i < this->CountBlock("uplink"); ++i) { Block *uplink = this->GetBlock("uplink", i); @@ -599,6 +621,8 @@ Conf::~Conf() { for (unsigned i = 0; i < MyOperTypes.size(); ++i) delete MyOperTypes[i]; + + delete locale; } void Conf::Post(Conf *old) diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 03dda8d18..265cb362b 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -23,6 +23,10 @@ #include "anope.h" #include "config.h" +#ifdef Boost_FOUND +#include <boost/locale.hpp> +#endif + unsigned char Anope::tolower(unsigned char c) { if (!Config || !Config->CaseMapLower[c]) @@ -164,3 +168,77 @@ bool sepstream::StreamEnd() return this->pos > this->tokens.length(); } +size_t Anope::hash::operator()(const Anope::string &s) const +{ + return std::hash<std::string>()(s.str()); +} + +bool Anope::compare::operator()(const Anope::string &s1, const Anope::string &s2) const +{ + return s1.equals_cs(s2); +} + +size_t Anope::hash_ci::operator()(const Anope::string &s) const +{ + return std::hash<std::string>()(s.lower().str()); +} + +bool Anope::compare_ci::operator()(const Anope::string &s1, const Anope::string &s2) const +{ + return s1.equals_ci(s2); +} + +size_t Anope::hash_locale::operator()(const Anope::string &s) const +{ +#ifdef Boost_FOUND + if (Config != nullptr && Config->locale != nullptr) + { + return Anope::locale::hash(s.str()); + } +#endif + + return Anope::hash_ci()(s); +} + +bool Anope::compare_locale::operator()(const Anope::string &s1, const Anope::string &s2) const +{ +#ifdef Boost_FOUND + if (Config != nullptr && Config->locale != nullptr) + { + return Anope::locale::compare(s1.str(), s2.str()) == 0; + } +#endif + + return Anope::compare_ci()(s1, s2); +} + +#ifdef Boost_FOUND + +std::locale Anope::locale::generate(const std::string &name) +{ + boost::locale::generator gen; + return gen.generate(name); +} + +int Anope::locale::compare(const std::string &s1, const std::string &s2) +{ + std::string c1 = boost::locale::conv::between(s1.data(), s1.data() + s1.length(), + Config->locale->name(), + ""); + + std::string c2 = boost::locale::conv::between(s2.data(), s2.data() + s2.length(), + Config->locale->name(), + ""); + + const boost::locale::collator<char> &ct = std::use_facet<boost::locale::collator<char>>(*Config->locale); + return ct.compare(boost::locale::collator_base::secondary, c1, c2); +} + +long Anope::locale::hash(const std::string &s) +{ + const boost::locale::collator<char> &ct = std::use_facet<boost::locale::collator<char>>(*Config->locale); + return ct.hash(boost::locale::collator_base::secondary, s.data(), s.data() + s.length()); +} + +#endif + diff --git a/src/users.cpp b/src/users.cpp index a8d7642c9..f107d8fb3 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -32,7 +32,8 @@ #include "event.h" #include "modules/nickserv.h" -user_map UserListByNick, UserListByUID; +user_map UserListByNick; +uid_map UserListByUID; int OperCount = 0; @@ -832,7 +833,7 @@ User* User::Find(const Anope::string &name, bool nick_only) { if (!nick_only && IRCD->RequiresID) { - user_map::iterator it = UserListByUID.find(name); + uid_map::iterator it = UserListByUID.find(name); if (it != UserListByUID.end()) return it->second; |