OpenTTD Source 15.0-RC2
stringfilter_type.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef STRINGFILTER_TYPE_H
11#define STRINGFILTER_TYPE_H
12
13#include "strings_type.h"
14
31private:
33 struct WordState {
34 std::string word;
35 bool match;
36 };
37
38 std::vector<WordState> word_index;
39 uint word_matches = 0;
40
41 const bool *case_sensitive;
43
44public:
50
51 void SetFilterTerm(std::string_view str);
52
57 bool IsEmpty() const { return this->word_index.empty(); }
58
59 void ResetState();
60 void AddLine(const char *) = delete; // prevent implicit construction of string_view from potential nullptr
61 void AddLine(std::string_view str);
62
67 bool GetState() const { return this->word_matches == this->word_index.size(); }
68};
69
70#endif /* STRINGFILTER_TYPE_H */
Types related to strings.
State of a single filter word.
bool match
Already matched?
std::string word
Word to filter for.
String filter and state.
StringFilter(const bool *case_sensitive=nullptr, bool locale_aware=true)
Constructor for filter.
bool IsEmpty() const
Check whether any filter words were entered.
uint word_matches
Summary of filter state: Number of words matched.
void SetFilterTerm(std::string_view str)
Set the term to filter on.
std::vector< WordState > word_index
Word index and filter state.
bool locale_aware
Match words using the current locale.
void ResetState()
Reset the matching state to process a new item.
const bool * case_sensitive
Match case-sensitively (usually a static variable).
bool GetState() const
Get the matching state of the current item.