Allow search with unicode characters and space

This commit is contained in:
Benau 2018-09-05 13:37:30 +08:00
parent 30028cc330
commit d0b24487eb
2 changed files with 10 additions and 31 deletions

View File

@ -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<core::stringw> 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

View File

@ -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;
}
}