OpenTTD: StringFilter Struct Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- Data Structures
- Class Hierarchy
- Data Fields

Data Structures | Public Member Functions | Private Attributes
StringFilter Struct Reference

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=NULL)
| Constructor for filter.
void | SetFilterTerm (const char *str)
| Set the term to filter on.
bool | IsEmpty () const
| Check whether any filter words were entered.
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.
void | AddLine (StringID str)
| Pass another text line from the current item to the filter.
bool | GetState () const
| Get the matching state of the current item.

## Private Attributes
const char * | filter_buffer
| Parsed filter string. Words separated by 0.
SmallVector< WordState, 4 > | 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).

## Detailed Description

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.

1. For every item first call ResetState() which resets the matching-state.
2. Pass all lines of the item via AddLine() to the filter.
3. Check the matching-result for the item via GetState().

Definition at line 33 of file stringfilter_type.h.

## Constructor & Destructor Documentation

StringFilter::StringFilter | ( | const bool * | case_sensitive = `NULL` | ) |
| inline

Constructor for filter.

Parameters

  case_sensitive | Pointer to a (usually static) variable controlling the case-sensitivity. NULL means always case-insensitive.

Definition at line 52 of file stringfilter_type.h.

## Member Function Documentation

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().

Parameters

  str | Another line from the item.

Definition at line 108 of file stringfilter.cpp.

References SmallVector< T, S >::Begin(), case_sensitive, SmallVector< T, S >::End(), StringFilter::WordState::match, word_index, and word_matches.

Referenced by AddLine(), AIDebugWindow::OnInvalidateData(), SignList::SignNameFilter(), NetworkContentListWindow::TagNameFilter(), NewGRFWindow::TagNameFilter(), SettingEntry::UpdateFilterState(), and SettingsPage::UpdateFilterState().

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().

Parameters

  str | Another line from the item.

Definition at line 132 of file stringfilter.cpp.

References AddLine(), DRAW_STRING_BUFFER, and lastof.

bool StringFilter::GetState | ( |  | ) | const
| inline

Get the matching state of the current item.

Returns
  true if matched.

Definition at line 71 of file stringfilter_type.h.

References SmallVector< T, S >::Length(), word_index, and word_matches.

Referenced by AIDebugWindow::OnInvalidateData(), SignList::SignNameFilter(), NetworkContentListWindow::TagNameFilter(), NewGRFWindow::TagNameFilter(), SettingEntry::UpdateFilterState(), and SettingsPage::UpdateFilterState().

bool StringFilter::IsEmpty | ( |  | ) | const
| inline

Check whether any filter words were entered.

Returns
  true if no words were entered.

Definition at line 61 of file stringfilter_type.h.

References SmallVector< T, S >::Length(), and word_index.

Referenced by NetworkGameWindow::BuildGUINetworkGameList(), NetworkContentListWindow::FilterContentList(), GameSettingsWindow::OnEditboxChanged(), SignListWindow::OnInvalidateData(), AIDebugWindow::OnInvalidateData(), GameSettingsWindow::OnInvalidateData(), NetworkContentListWindow::UpdateFilterState(), SettingEntry::UpdateFilterState(), and SettingsPage::UpdateFilterState().

void StringFilter::SetFilterTerm | ( | const char * | str | ) |

Set the term to filter on.

Parameters

  str | Filter term

Definition at line 29 of file stringfilter.cpp.

References SmallVector< T, S >::Append(), filter_buffer, free(), IsWhitespace(), StringFilter::WordState::match, SmallVector< T, S >::Reset(), StringFilter::WordState::start, Utf8Decode(), word_index, and word_matches.

Referenced by NetworkGameWindow::BuildGUINetworkGameList(), AIDebugWindow::OnEditboxChanged(), GameSettingsWindow::OnEditboxChanged(), and SignListWindow::SetFilterString().

The documentation for this struct was generated from the following files:

- src/stringfilter_type.h
- src/stringfilter.cpp