OpenTTD Source 15.0-beta1
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 <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef STRINGFILTER_TYPE_H
11#define STRINGFILTER_TYPE_H
12
13#include "strings_type.h"
14
31private:
33 struct WordState {
34 const char *start;
35 bool match;
36 };
37
38 const char *filter_buffer;
39 std::vector<WordState> word_index;
41
42 const bool *case_sensitive;
44
45public:
51 ~StringFilter() { free(this->filter_buffer); }
52
53 void SetFilterTerm(const char *str);
54 void SetFilterTerm(const std::string &str);
55
60 bool IsEmpty() const { return this->word_index.empty(); }
61
62 void ResetState();
63 void AddLine(const char *str);
64 void AddLine(const std::string &str);
65 void AddLine(StringID str);
66
71 bool GetState() const { return this->word_matches == this->word_index.size(); }
72};
73
74#endif /* STRINGFILTER_TYPE_H */
void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition stdafx.h:334
Types related to strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
State of a single filter word.
bool match
Already matched?
const char * start
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.
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.
bool GetState() const
Get the matching state of the current item.