From d0b24487eba5a282642bb136386d15116040e177 Mon Sep 17 00:00:00 2001 From: Benau Date: Wed, 5 Sep 2018 13:37:30 +0800 Subject: [PATCH] Allow search with unicode characters and space --- src/network/server.cpp | 28 ++-------------------------- src/network/server.hpp | 13 ++++++++----- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/network/server.cpp b/src/network/server.cpp index 80dbeeeba..5bf7216e0 100644 --- a/src/network/server.cpp +++ b/src/network/server.cpp @@ -48,7 +48,8 @@ Server::Server(const XMLNode& server_info) : m_supports_encrytion(true) xml.get("name", &m_lower_case_name); m_name = StringUtils::xmlDecode(m_lower_case_name); - m_lower_case_name = StringUtils::toLowerCase(m_lower_case_name); + m_lower_case_name = StringUtils::toLowerCase( + StringUtils::wideToUtf8(m_name)); xml.get("id", &m_server_id); xml.get("host_id", &m_server_owner); @@ -179,28 +180,3 @@ Server::Server(unsigned server_id, const core::stringw &name, int max_players, m_official = false; m_game_started = game_started; } // server(server_id, ...) - -// ---------------------------------------------------------------------------- -/** \brief Filter the add-on with a list of words. - * \param words A list of words separated by ' '. - * \return true if the add-on contains one of the words, otherwise false. - */ -bool Server::filterByWords(const core::stringw words) const -{ - if (words == NULL || words.empty()) - return true; - - std::vector list = StringUtils::split(words, ' ', false); - - for (unsigned int i = 0; i < list.size(); i++) - { - list[i].make_lower(); - - if ((core::stringw(m_name).make_lower()).find(list[i].c_str()) != -1) - { - return true; - } - } - - return false; -} // filterByWords diff --git a/src/network/server.hpp b/src/network/server.hpp index 86e092c7d..6833ac262 100644 --- a/src/network/server.hpp +++ b/src/network/server.hpp @@ -101,7 +101,6 @@ public: int max_players, int current_players, unsigned difficulty, unsigned server_mode, const TransportAddress &address, bool password_protected, bool game_started); - bool filterByWords(const irr::core::stringw words) const; // ------------------------------------------------------------------------ /** Returns ip address and port of this server. */ const TransportAddress& getAddress() const { return m_address; } @@ -152,13 +151,17 @@ public: // ------------------------------------------------------------------------ bool searchByName(const std::string& lower_case_word) { - bool server_name_found = - m_lower_case_name.find(lower_case_word) != std::string::npos; - if (!server_name_found) + auto list = StringUtils::split(lower_case_word, ' ', false); + bool server_name_found = false; + for (auto& word : list) { + server_name_found = + m_lower_case_name.find(word) != std::string::npos; + if (server_name_found) + break; for (auto& p : m_players) { - if (p.first.find(lower_case_word) != std::string::npos) + if (p.first.find(word) != std::string::npos) return true; } }