OpenTTD
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;
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 */
bool match
Already matched?
Simple vector class that allows allocating an item without the need to copy this->data needlessly...
void ResetState()
Reset the matching state to process a new item.
bool GetState() const
Get the matching state of the current item.
String filter and state.
Simple vector template class.
const char * filter_buffer
Parsed filter string. Words separated by 0.
void SetFilterTerm(const char *str)
Set the term to filter on.
uint Length() const
Get the number of items in the list.
const char * start
Word to filter for.
uint word_matches
Summary of filter state: Number of words matched.
StringFilter(const bool *case_sensitive=NULL)
Constructor for filter.
State of a single filter word.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
void AddLine(const char *str)
Pass another text line from the current item to the filter.
const bool * case_sensitive
Match case-sensitively (usually a static variable).
Types related to strings.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
SmallVector< WordState, 4 > word_index
Word index and filter state.
bool IsEmpty() const
Check whether any filter words were entered.