Skip to content

Commit

Permalink
Replace a search in filters by translation::ci_search
Browse files Browse the repository at this point in the history
  • Loading branch information
dvladf authored and Vultraz committed Jan 27, 2019
1 parent 0f00da0 commit a25a43e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 39 deletions.
4 changes: 1 addition & 3 deletions src/gui/dialogs/preferences_dialog.cpp
Expand Up @@ -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;
}
Expand Down
18 changes: 3 additions & 15 deletions src/gui/dialogs/unit_create.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 1 addition & 6 deletions src/gui/dialogs/unit_recall.cpp
Expand Up @@ -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()
Expand Down
17 changes: 2 additions & 15 deletions src/gui/dialogs/unit_recruit.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a25a43e

Please sign in to comment.