Remove the use of wxRegex for case-insensitive filtering

This commit is contained in:
Thomas Goyne 2013-04-13 08:21:28 -07:00
parent 17170fc5fe
commit 4e7d6df6b2
2 changed files with 9 additions and 17 deletions

View file

@ -142,7 +142,6 @@
#include <wx/radiobut.h>
#include <wx/rawbmp.h>
#include <wx/recguard.h>
#include <wx/regex.h>
#include <wx/sashwin.h>
#include <wx/scrolbar.h>
#include <wx/settings.h>

View file

@ -33,7 +33,6 @@
#include "preferences.h"
#include <wx/dataview.h>
#include <wx/regex.h>
#include <algorithm>
#include <list>
@ -75,8 +74,8 @@ public:
{
}
bool IsVisible(wxRegEx const& filter) const {
return filter.Matches(cmd_name) || filter.Matches(cmd_str);
bool IsVisible(wxString const& filter) const {
return cmd_name.Lower().Contains(filter) || cmd_str.Contains(filter);
}
void Apply(Hotkey::HotkeyMap *hk_map) {
@ -166,7 +165,7 @@ public:
combo.Apply(hk_map);
}
void SetFilter(wxRegEx const& new_filter) {
void SetFilter(wxString const& new_filter) {
std::set<HotkeyModelCombo*> old_visible;
for (auto item : visible_items)
old_visible.insert(static_cast<HotkeyModelCombo*>(item.GetID()));
@ -235,19 +234,13 @@ public:
}
void Apply(Hotkey::HotkeyMap *hk_map) {
for_each(categories.begin(), categories.end(),
bind(&HotkeyModelCategory::Apply, std::placeholders::_1, hk_map));
for (auto& category : categories)
category.Apply(hk_map);
}
void SetFilter(wxString filter) {
// Escape any regular-expression special characters
static wxRegEx escape_meta("[-[\\]{}()*+?.,\\\\^$|#]", wxRE_ADVANCED);
escape_meta.Replace(&filter, "\\\\&");
// Using wxRegEx for case-insensitive contains
wxRegEx re(filter, wxRE_ADVANCED | wxRE_ICASE | wxRE_NOSUB);
for_each(categories.begin(), categories.end(),
bind(&HotkeyModelCategory::SetFilter, std::placeholders::_1, std::ref(re)));
void SetFilter(wxString const& filter) {
for (auto& category : categories)
category.SetFilter(filter);
}
wxDataViewItem GetParent() const { return wxDataViewItem(0); }
@ -338,5 +331,5 @@ void HotkeyDataViewModel::Apply() {
}
void HotkeyDataViewModel::SetFilter(wxString const& filter) {
root->SetFilter(filter);
root->SetFilter(filter.Lower());
}