20 static const WChar STATE_WHITESPACE =
' ';
21 static const WChar STATE_WORD =
'w';
22 static const WChar STATE_QUOTE1 =
'\'';
23 static const WChar STATE_QUOTE2 =
'"';
37 char *dest = MallocT<char>(strlen(str) + 1);
40 WChar state = STATE_WHITESPACE;
41 const char *pos = str;
48 if (c == 0 || (state == STATE_WORD &&
IsWhitespace(c))) {
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) {
83 memcpy(dest, pos, len);
110 if (str == NULL)
return;
116 if ((match_case ? strstr(str, it->start) : strcasestr(str, it->start)) != NULL) {
135 GetString(buffer, str,
lastof(buffer));
Functions related to OTTD's strings.
bool match
Already matched?
void ResetState()
Reset the matching state to process a new item.
static bool IsWhitespace(WChar c)
Check whether UNICODE character is whitespace or not, i.e.
static const int DRAW_STRING_BUFFER
Size of the buffer used for drawing strings.
size_t Utf8Decode(WChar *c, const char *s)
Decode and consume the next UTF-8 encoded character.
#define lastof(x)
Get the last element of an fixed size array.
const char * filter_buffer
Parsed filter string. Words separated by 0.
void SetFilterTerm(const char *str)
Set the term to filter on.
Functions related to low-level strings.
const char * start
Word to filter for.
Functions related to the gfx engine.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
uint word_matches
Summary of filter state: Number of words matched.
State of a single filter word.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Searching and filtering using a stringterm.
const bool * case_sensitive
Match case-sensitively (usually a static variable).
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
SmallVector< WordState, 4 > word_index
Word index and filter state.
uint32 WChar
Type for wide characters, i.e.