OpenTTD Source
20241108-master-g80f628063a
|
String filter and state. More...
#include <stringfilter_type.h>
Data Structures | |
struct | WordState |
State of a single filter word. More... | |
Public Member Functions | |
StringFilter (const bool *case_sensitive=nullptr, bool locale_aware=true) | |
Constructor for filter. More... | |
void | SetFilterTerm (const char *str) |
Set the term to filter on. More... | |
void | SetFilterTerm (const std::string &str) |
Set the term to filter on. More... | |
bool | IsEmpty () const |
Check whether any filter words were entered. More... | |
void | ResetState () |
Reset the matching state to process a new item. | |
void | AddLine (const char *str) |
Pass another text line from the current item to the filter. More... | |
void | AddLine (const std::string &str) |
Pass another text line from the current item to the filter. More... | |
void | AddLine (StringID str) |
Pass another text line from the current item to the filter. More... | |
bool | GetState () const |
Get the matching state of the current item. More... | |
Private Attributes | |
const char * | filter_buffer |
Parsed filter string. Words separated by 0. | |
std::vector< WordState > | word_index |
Word index and filter state. | |
uint | word_matches |
Summary of filter state: Number of words matched. | |
const bool * | case_sensitive |
Match case-sensitively (usually a static variable). | |
bool | locale_aware |
Match words using the current locale. | |
String filter and state.
The filter takes a stringterm and parses it into words separated by whitespace. The whitespace-separation can be avoided by quoting words in the searchterm using " or '. The quotation characters can be nested or concatenated in a unix-shell style.
When filtering an item, all words are checked for matches, and the filter matches if every word matched. So, effectively this is a AND search for all entered words.
Once the filter is set up using SetFilterTerm, multiple items can be filtered consecutively.
Definition at line 30 of file stringfilter_type.h.
|
inline |
Constructor for filter.
case_sensitive | Pointer to a (usually static) variable controlling the case-sensitivity. nullptr means always case-insensitive. |
Definition at line 50 of file stringfilter_type.h.
void StringFilter::AddLine | ( | const char * | str | ) |
Pass another text line from the current item to the filter.
You can call this multiple times for a single item, if the filter shall apply to multiple things. Before processing the next item you have to call ResetState().
str | Another line from the item. |
Definition at line 114 of file stringfilter.cpp.
References case_sensitive, locale_aware, StrNaturalContains(), StrNaturalContainsIgnoreCase(), word_index, and word_matches.
Referenced by AddLine(), IndustryDirectoryWindow::BuildSortIndustriesList(), ClassTagNameFilter(), BuildVehicleWindow::FilterByText(), ScriptDebugWindow::OnInvalidateData(), SignList::SignNameFilter(), NetworkContentListWindow::TagNameFilter(), NewGRFWindow::TagNameFilter(), TypeTagNameFilter(), SettingEntry::UpdateFilterState(), and SettingsPage::UpdateFilterState().
void StringFilter::AddLine | ( | const std::string & | str | ) |
Pass another text line from the current item to the filter.
You can call this multiple times for a single item, if the filter shall apply to multiple things. Before processing the next item you have to call ResetState().
str | Another line from the item. |
Definition at line 144 of file stringfilter.cpp.
References AddLine().
void StringFilter::AddLine | ( | StringID | str | ) |
Pass another text line from the current item to the filter.
You can call this multiple times for a single item, if the filter shall apply to multiple things. Before processing the next item you have to call ResetState().
str | Another line from the item. |
Definition at line 157 of file stringfilter.cpp.
References AddLine(), and GetString().
|
inline |
Get the matching state of the current item.
Definition at line 71 of file stringfilter_type.h.
Referenced by IndustryDirectoryWindow::BuildSortIndustriesList(), ClassTagNameFilter(), BuildVehicleWindow::FilterByText(), ScriptDebugWindow::OnInvalidateData(), SignList::SignNameFilter(), NetworkContentListWindow::TagNameFilter(), NewGRFWindow::TagNameFilter(), TypeTagNameFilter(), SettingEntry::UpdateFilterState(), and SettingsPage::UpdateFilterState().
|
inline |
Check whether any filter words were entered.
Definition at line 60 of file stringfilter_type.h.
Referenced by IndustryDirectoryWindow::BuildSortIndustriesList(), BuildVehicleWindow::FilterByText(), NetworkContentListWindow::FilterContentList(), NetworkContentListWindow::OnInvalidateData(), GameSettingsWindow::OnInvalidateData(), SignListWindow::OnInvalidateData(), NetworkContentListWindow::UpdateFilterState(), SettingEntry::UpdateFilterState(), and SettingsPage::UpdateFilterState().
void StringFilter::SetFilterTerm | ( | const char * | str | ) |
Set the term to filter on.
str | Filter term |
Definition at line 28 of file stringfilter.cpp.
References filter_buffer, free(), word_index, and word_matches.
Referenced by ScriptDebugWindow::ScriptDebugWindow(), SignListWindow::SetFilterString(), and SetFilterTerm().
void StringFilter::SetFilterTerm | ( | const std::string & | str | ) |
Set the term to filter on.
str | Filter term |
Definition at line 90 of file stringfilter.cpp.
References SetFilterTerm().