18static const char32_t STATE_WHITESPACE =
' ';
19static const char32_t STATE_WORD =
'w';
20static const char32_t STATE_QUOTE1 =
'\'';
21static const char32_t STATE_QUOTE2 =
'"';
33 char32_t state = STATE_WHITESPACE;
34 auto pos = str.begin();
35 auto word_begin = str.end();
39 auto add_word = [&] () {
40 if (word_begin != str.end()) {
41 this->
word_index.emplace_back(std::string(word_begin, word_end + 1),
false);
42 word_begin = str.end();
46 for (
size_t len; pos < str.end(); pos += len) {
53 state = STATE_WHITESPACE;
57 if (state == STATE_WHITESPACE) {
63 if (c == STATE_QUOTE1 || c == STATE_QUOTE2) {
68 }
else if (state == STATE_WORD) {
76 if (word_begin == str.end()) {
107 if (str ==
nullptr)
return;
118 if ((match_case ? strstr(str, ws.word.c_str()) : strcasestr(str, ws.word.c_str())) !=
nullptr) {
Functions related to the gfx engine.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
bool StrNaturalContains(const std::string_view str, const std::string_view value)
Checks if a string is contained in another string with a locale-aware comparison that is case sensiti...
size_t Utf8Decode(char32_t *c, const char *s)
Decode and consume the next UTF-8 encoded character.
bool StrNaturalContainsIgnoreCase(const std::string_view str, const std::string_view value)
Checks if a string is contained in another string with a locale-aware comparison that is case insensi...
Functions related to low-level strings.
bool IsWhitespace(char32_t c)
Check whether UNICODE character is whitespace or not, i.e.
Searching and filtering using a stringterm.
Functions related to OTTD's strings.
State of a single filter word.
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).
void AddLine(const char *str)
Pass another text line from the current item to the filter.