OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

stringfilter_type.h
Go to the documentation of this file.
1 /* $Id: stringfilter_type.h 24632 2012-10-27 15:26:17Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef STRINGFILTER_TYPE_H
13 #define STRINGFILTER_TYPE_H
14
15 #include "core/smallvec_type.hpp"
16 #include "strings_type.h"
17
33 struct StringFilter {
34 private:
36 struct WordState {
37 const char *start;
38 bool match;
39 };
40
41 const char *filter_buffer;
42 SmallVector<WordState, 4> word_index;
43 uint word_matches;
44
45 const bool *case_sensitive;
46
47 public:
52 StringFilter(const bool *case_sensitive = NULL) : filter_buffer(NULL), word_matches(0), case_sensitive(case_sensitive) {}
53 ~StringFilter() { free(this->filter_buffer); }
54
55 void SetFilterTerm(const char *str);
56
61 bool IsEmpty() const { return this->word_index.Length() == 0; }
62
63 void ResetState();
64 void AddLine(const char *str);
65 void AddLine(StringID str);
66
71 bool GetState() const { return this->word_matches == this->word_index.Length(); }
72 };
73
74 #endif /* STRINGFILTER_TYPE_H */