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