Replace a search in filters by translation::ci_search

This commit is contained in:
Vlad Drozdov 2019-01-07 13:55:27 +08:00 committed by Charles Dang
parent 0f00da0995
commit a25a43e1ac
4 changed files with 7 additions and 39 deletions

View file

@ -941,9 +941,7 @@ void preferences_dialog::hotkey_filter_callback(window& window) const
if(!text.empty()) {
for(const auto& word : utils::split(text, ' ')) {
found = std::search(description.begin(), description.end(), word.begin(), word.end(), chars_equal_insensitive)
!= description.end();
found = translation::ci_search(description, word);
if(!found) {
break;
}

View file

@ -205,18 +205,6 @@ void unit_create::list_item_clicked(window& window)
});
}
namespace
{
bool ci_search(const std::string& a, const std::string& b)
{
return std::search(a.begin(), a.end(),
b.begin(), b.end(),
chars_equal_insensitive) != a.end();
}
} // end unnamed namespace
void unit_create::filter_text_changed(text_box_base* textbox, const std::string& text)
{
window& window = *textbox->get_window();
@ -248,9 +236,9 @@ void unit_create::filter_text_changed(text_box_base* textbox, const std::string&
bool found = false;
for(const auto & word : words)
{
found = ci_search(type_label.get_label().str(), word) ||
ci_search(race_label.get_label().str(), word) ||
ci_search(unit_type_id, word);
found = translation::ci_search(type_label.get_label().str(), word) ||
translation::ci_search(race_label.get_label().str(), word) ||
translation::ci_search(unit_type_id, word);
if(!found) {
// one word doesn't match, we don't reach words.end()

View file

@ -391,12 +391,7 @@ void unit_recall::filter_text_changed(text_box_base* textbox, const std::string&
bool found = false;
for(const auto & word : words) {
found = std::search(filter_options_[i].begin(),
filter_options_[i].end(),
word.begin(),
word.end(),
chars_equal_insensitive)
!= filter_options_[i].end();
found = translation::ci_search(filter_options_[i], word);
if(!found) {
// one word doesn't match, we don't reach words.end()

View file

@ -57,18 +57,6 @@ static std::string can_afford_unit(const std::string& text, const bool can_affor
return can_afford ? text : "<span color='#ff0000'>" + text + "</span>";
}
namespace
{
bool ci_search(const std::string& a, const std::string& b)
{
return std::search(a.begin(), a.end(),
b.begin(), b.end(),
chars_equal_insensitive) != a.end();
}
} // end unnamed namespace
// Compare unit_create::filter_text_change
void unit_recruit::filter_text_changed(text_box_base* textbox, const std::string& text)
{
@ -96,9 +84,8 @@ void unit_recruit::filter_text_changed(text_box_base* textbox, const std::string
{
// Search for the name in the local language.
// In debug mode, also search for the type id.
found =
(game_config::debug && ci_search(type->id(), word)) ||
ci_search(type->type_name(), word);
found = (game_config::debug && translation::ci_search(type->id(), word)) ||
translation::ci_search(type->type_name(), word);
if(!found) {
// one word doesn't match, we don't reach words.end()