19 static const char32_t STATE_WHITESPACE =
' ';
20 static const char32_t STATE_WORD =
'w';
21 static const char32_t STATE_QUOTE1 =
'\'';
22 static const char32_t STATE_QUOTE2 =
'"';
35 assert(str !=
nullptr);
37 char *dest = MallocT<char>(strlen(str) + 1);
40 char32_t state = STATE_WHITESPACE;
41 const char *pos = str;
48 if (c == 0 || (state == STATE_WORD &&
IsWhitespace(c))) {
50 if (word !=
nullptr) {
54 state = STATE_WHITESPACE;
55 if (c != 0)
continue;
else break;
58 if (state == STATE_WHITESPACE) {
64 if (c == STATE_QUOTE1 || c == STATE_QUOTE2) {
69 }
else if (state == STATE_WORD) {
77 if (word ==
nullptr) {
81 memcpy(dest, pos, len);
116 if (str ==
nullptr)
return;
127 if ((match_case ? strstr(str, ws.start) : strcasestr(str, ws.start)) !=
nullptr) {
Functions related to the allocation of memory.
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.
void free(const void *ptr)
Version of the standard free that accepts const pointers.
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.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
State of a single filter word.
uint word_matches
Summary of filter state: Number of words matched.
const char * filter_buffer
Parsed filter string. Words separated by 0.
std::vector< WordState > word_index
Word index and filter state.
void SetFilterTerm(const char *str)
Set the term to filter on.
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.