Mercurial > hg > openttd
annotate src/stringfilter.cpp @ 20706:79930f9362c3 draft
-Change: [Win32] Position the IME composition window at the caret position.
author | Michael Lutz <michi@icosahedron.de> |
---|---|
date | Sun, 07 Apr 2013 17:10:38 +0200 (2013-04-07) |
parents | 817b521c2b1a |
children |
rev | line source |
---|---|
19434
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
2 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
3 /* |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
4 * This file is part of OpenTTD. |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
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. |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
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. |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
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/>. |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
8 */ |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
9 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
10 /** @file stringfilter.cpp Searching and filtering using a stringterm. */ |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
11 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
12 #include "stdafx.h" |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
13 #include "string_func.h" |
19711
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
14 #include "strings_func.h" |
19434
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
15 #include "stringfilter_type.h" |
19711
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
16 #include "gfx_func.h" |
19434
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
17 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
18 static const WChar STATE_WHITESPACE = ' '; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
19 static const WChar STATE_WORD = 'w'; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
20 static const WChar STATE_QUOTE1 = '\''; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
21 static const WChar STATE_QUOTE2 = '"'; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
22 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
23 /** |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
24 * Set the term to filter on. |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
25 * @param str Filter term |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
26 */ |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
27 void StringFilter::SetFilterTerm(const char *str) |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
28 { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
29 this->word_index.Reset(); |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
30 this->word_matches = 0; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
31 free(this->filter_buffer); |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
32 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
33 assert(str != NULL); |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
34 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
35 char *dest = (char *)malloc(strlen(str) + 1); |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
36 this->filter_buffer = dest; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
37 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
38 WChar state = STATE_WHITESPACE; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
39 const char *pos = str; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
40 WordState *word = NULL; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
41 size_t len; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
42 for (;; pos += len) { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
43 WChar c; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
44 len = Utf8Decode(&c, pos); |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
45 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
46 if (c == 0 || (state == STATE_WORD && IsWhitespace(c))) { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
47 /* Finish word */ |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
48 if (word != NULL) { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
49 *(dest++) = '\0'; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
50 word = NULL; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
51 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
52 state = STATE_WHITESPACE; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
53 if (c != 0) continue; else break; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
54 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
55 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
56 if (state == STATE_WHITESPACE) { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
57 /* Skip whitespace */ |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
58 if (IsWhitespace(c)) continue; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
59 state = STATE_WORD; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
60 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
61 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
62 if (c == STATE_QUOTE1 || c == STATE_QUOTE2) { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
63 if (state == c) { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
64 /* Stop quoting */ |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
65 state = STATE_WORD; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
66 continue; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
67 } else if (state == STATE_WORD) { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
68 /* Start quoting */ |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
69 state = c; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
70 continue; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
71 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
72 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
73 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
74 /* Add to word */ |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
75 if (word == NULL) { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
76 word = this->word_index.Append(); |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
77 word->start = dest; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
78 word->match = false; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
79 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
80 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
81 memcpy(dest, pos, len); |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
82 dest += len; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
83 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
84 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
85 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
86 /** |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
87 * Reset the matching state to process a new item. |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
88 */ |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
89 void StringFilter::ResetState() |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
90 { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
91 this->word_matches = 0; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
92 const WordState *end = this->word_index.End(); |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
93 for (WordState *it = this->word_index.Begin(); it != end; ++it) { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
94 it->match = false; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
95 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
96 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
97 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
98 /** |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
99 * Pass another text line from the current item to the filter. |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
100 * |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
101 * You can call this multiple times for a single item, if the filter shall apply to multiple things. |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
102 * Before processing the next item you have to call ResetState(). |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
103 * |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
104 * @param str Another line from the item. |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
105 */ |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
106 void StringFilter::AddLine(const char *str) |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
107 { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
108 if (str == NULL) return; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
109 |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
110 bool match_case = this->case_sensitive != NULL && *this->case_sensitive; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
111 const WordState *end = this->word_index.End(); |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
112 for (WordState *it = this->word_index.Begin(); it != end; ++it) { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
113 if (!it->match) { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
114 if ((match_case ? strstr(str, it->start) : strcasestr(str, it->start)) != NULL) { |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
115 it->match = true; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
116 this->word_matches++; |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
117 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
118 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
119 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
120 } |
24df8a97401e
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents:
diff
changeset
|
121 |
19711
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
122 /** |
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
123 * Pass another text line from the current item to the filter. |
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
124 * |
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
125 * You can call this multiple times for a single item, if the filter shall apply to multiple things. |
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
126 * Before processing the next item you have to call ResetState(). |
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
127 * |
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
128 * @param str Another line from the item. |
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
129 */ |
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
130 void StringFilter::AddLine(StringID str) |
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
131 { |
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
132 char buffer[DRAW_STRING_BUFFER]; |
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
133 GetString(buffer, str, lastof(buffer)); |
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
134 AddLine(buffer); |
817b521c2b1a
(svn r24632) -Feature: Add text filtering to advanced settings.
frosch <frosch@openttd.org>
parents:
19434
diff
changeset
|
135 } |