# stringfilter_type.h

Go to the documentation of this file.

    00001 /* $Id: stringfilter_type.h 24632 2012-10-27 15:26:17Z frosch $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef STRINGFILTER_TYPE_H
    00013 #define STRINGFILTER_TYPE_H
    00014
    00015 #include "core/smallvec_type.hpp"
    00016 #include "strings_type.h"
    00017
    00033 struct StringFilter {
    00034 private:
    00036   struct WordState {
    00037     const char *start;
    00038     bool match;
    00039   };
    00040
    00041   const char *filter_buffer;
    00042   SmallVector<WordState, 4> word_index;
    00043   uint word_matches;
    00044
    00045   const bool *case_sensitive;
    00046
    00047 public:
    00052   StringFilter(const bool *case_sensitive = NULL) : filter_buffer(NULL), word_matches(0), case_sensitive(case_sensitive) {}
    00053   ~StringFilter() { free(this->filter_buffer); }
    00054
    00055   void SetFilterTerm(const char *str);
    00056
    00061   bool IsEmpty() const { return this->word_index.Length() == 0; }
    00062
    00063   void ResetState();
    00064   void AddLine(const char *str);
    00065   void AddLine(StringID str);
    00066
    00071   bool GetState() const { return this->word_matches == this->word_index.Length(); }
    00072 };
    00073
    00074 #endif /* STRINGFILTER_TYPE_H */