Eugene Klyuchnikov | 771eb10 | 2015-11-27 11:27:11 +0100 | [diff] [blame] | 1 | /* Copyright 2013 Google Inc. All Rights Reserved. |
| 2 | |
Eugene Klyuchnikov | 24ffa78 | 2015-12-11 11:11:51 +0100 | [diff] [blame] | 3 | Distributed under MIT license. |
Eugene Klyuchnikov | 771eb10 | 2015-11-27 11:27:11 +0100 | [diff] [blame] | 4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
| 5 | */ |
| 6 | |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 7 | #include "./static_dict.h" |
| 8 | |
Eugene Kliuchnikov | 0282918 | 2016-06-03 10:51:04 +0200 | [diff] [blame] | 9 | #include "../common/dictionary.h" |
Eugene Kliuchnikov | da254cf | 2017-12-12 14:33:12 +0100 | [diff] [blame] | 10 | #include "../common/platform.h" |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 11 | #include "../common/transform.h" |
| 12 | #include "./encoder_dict.h" |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 13 | #include "./find_match_length.h" |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 14 | |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 15 | #if defined(__cplusplus) || defined(c_plusplus) |
| 16 | extern "C" { |
| 17 | #endif |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 18 | |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 19 | /* TODO: use BrotliTransforms.cutOffTransforms instead. */ |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 20 | static const uint8_t kOmitLastNTransforms[10] = { |
| 21 | 0, 12, 27, 23, 42, 63, 56, 48, 59, 64, |
| 22 | }; |
| 23 | |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 24 | static BROTLI_INLINE uint32_t Hash(const uint8_t* data) { |
Eugene Kliuchnikov | da254cf | 2017-12-12 14:33:12 +0100 | [diff] [blame] | 25 | uint32_t h = BROTLI_UNALIGNED_LOAD32LE(data) * kDictHashMul32; |
Eugene Kliuchnikov | 352b0b2 | 2016-06-03 11:19:23 +0200 | [diff] [blame] | 26 | /* The higher bits contain more mixture from the multiplication, |
| 27 | so we take our results from there. */ |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 28 | return h >> (32 - kDictNumBits); |
| 29 | } |
| 30 | |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 31 | static BROTLI_INLINE void AddMatch(size_t distance, size_t len, size_t len_code, |
| 32 | uint32_t* matches) { |
| 33 | uint32_t match = (uint32_t)((distance << 5) + len_code); |
| 34 | matches[len] = BROTLI_MIN(uint32_t, matches[len], match); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 35 | } |
| 36 | |
Eugene Kliuchnikov | cdca91b | 2017-03-06 14:22:45 +0100 | [diff] [blame] | 37 | static BROTLI_INLINE size_t DictMatchLength(const BrotliDictionary* dictionary, |
| 38 | const uint8_t* data, |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 39 | size_t id, |
| 40 | size_t len, |
| 41 | size_t maxlen) { |
Eugene Kliuchnikov | cdca91b | 2017-03-06 14:22:45 +0100 | [diff] [blame] | 42 | const size_t offset = dictionary->offsets_by_length[len] + len * id; |
| 43 | return FindMatchLengthWithLimit(&dictionary->data[offset], data, |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 44 | BROTLI_MIN(size_t, len, maxlen)); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 45 | } |
| 46 | |
Eugene Kliuchnikov | cdca91b | 2017-03-06 14:22:45 +0100 | [diff] [blame] | 47 | static BROTLI_INLINE BROTLI_BOOL IsMatch(const BrotliDictionary* dictionary, |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 48 | DictWord w, const uint8_t* data, size_t max_length) { |
| 49 | if (w.len > max_length) { |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 50 | return BROTLI_FALSE; |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 51 | } else { |
Eugene Kliuchnikov | cdca91b | 2017-03-06 14:22:45 +0100 | [diff] [blame] | 52 | const size_t offset = dictionary->offsets_by_length[w.len] + |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 53 | (size_t)w.len * (size_t)w.idx; |
Eugene Kliuchnikov | cdca91b | 2017-03-06 14:22:45 +0100 | [diff] [blame] | 54 | const uint8_t* dict = &dictionary->data[offset]; |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 55 | if (w.transform == 0) { |
Eugene Kliuchnikov | 352b0b2 | 2016-06-03 11:19:23 +0200 | [diff] [blame] | 56 | /* Match against base dictionary word. */ |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 57 | return |
| 58 | TO_BROTLI_BOOL(FindMatchLengthWithLimit(dict, data, w.len) == w.len); |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 59 | } else if (w.transform == 10) { |
Eugene Kliuchnikov | 352b0b2 | 2016-06-03 11:19:23 +0200 | [diff] [blame] | 60 | /* Match against uppercase first transform. |
| 61 | Note that there are only ASCII uppercase words in the lookup table. */ |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 62 | return TO_BROTLI_BOOL(dict[0] >= 'a' && dict[0] <= 'z' && |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 63 | (dict[0] ^ 32) == data[0] && |
| 64 | FindMatchLengthWithLimit(&dict[1], &data[1], w.len - 1u) == |
| 65 | w.len - 1u); |
| 66 | } else { |
Eugene Kliuchnikov | 352b0b2 | 2016-06-03 11:19:23 +0200 | [diff] [blame] | 67 | /* Match against uppercase all transform. |
| 68 | Note that there are only ASCII uppercase words in the lookup table. */ |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 69 | size_t i; |
| 70 | for (i = 0; i < w.len; ++i) { |
| 71 | if (dict[i] >= 'a' && dict[i] <= 'z') { |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 72 | if ((dict[i] ^ 32) != data[i]) return BROTLI_FALSE; |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 73 | } else { |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 74 | if (dict[i] != data[i]) return BROTLI_FALSE; |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 75 | } |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 76 | } |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 77 | return BROTLI_TRUE; |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 78 | } |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 82 | BROTLI_BOOL BrotliFindAllStaticDictionaryMatches( |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 83 | const BrotliEncoderDictionary* dictionary, const uint8_t* data, |
Eugene Kliuchnikov | da254cf | 2017-12-12 14:33:12 +0100 | [diff] [blame] | 84 | size_t min_length, size_t max_length, uint32_t* matches) { |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 85 | BROTLI_BOOL has_found_match = BROTLI_FALSE; |
| 86 | { |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 87 | size_t offset = dictionary->buckets[Hash(data)]; |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 88 | BROTLI_BOOL end = !offset; |
| 89 | while (!end) { |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 90 | DictWord w = dictionary->dict_words[offset++]; |
Eugene Kliuchnikov | 8d3fdc1 | 2017-01-26 11:32:18 +0100 | [diff] [blame] | 91 | const size_t l = w.len & 0x1F; |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 92 | const size_t n = (size_t)1 << dictionary->words->size_bits_by_length[l]; |
Zoltan Szabadka | 8844b7f | 2016-01-07 16:27:49 +0100 | [diff] [blame] | 93 | const size_t id = w.idx; |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 94 | end = !!(w.len & 0x80); |
| 95 | w.len = (uint8_t)l; |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 96 | if (w.transform == 0) { |
Eugene Kliuchnikov | cdca91b | 2017-03-06 14:22:45 +0100 | [diff] [blame] | 97 | const size_t matchlen = |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 98 | DictMatchLength(dictionary->words, data, id, l, max_length); |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 99 | const uint8_t* s; |
| 100 | size_t minlen; |
| 101 | size_t maxlen; |
| 102 | size_t len; |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 103 | /* Transform "" + BROTLI_TRANSFORM_IDENTITY + "" */ |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 104 | if (matchlen == l) { |
| 105 | AddMatch(id, l, l, matches); |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 106 | has_found_match = BROTLI_TRUE; |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 107 | } |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 108 | /* Transforms "" + BROTLI_TRANSFORM_OMIT_LAST_1 + "" and |
| 109 | "" + BROTLI_TRANSFORM_OMIT_LAST_1 + "ing " */ |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 110 | if (matchlen >= l - 1) { |
| 111 | AddMatch(id + 12 * n, l - 1, l, matches); |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 112 | if (l + 2 < max_length && |
| 113 | data[l - 1] == 'i' && data[l] == 'n' && data[l + 1] == 'g' && |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 114 | data[l + 2] == ' ') { |
| 115 | AddMatch(id + 49 * n, l + 3, l, matches); |
| 116 | } |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 117 | has_found_match = BROTLI_TRUE; |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 118 | } |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 119 | /* Transform "" + BROTLI_TRANSFORM_OMIT_LAST_# + "" (# = 2 .. 9) */ |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 120 | minlen = min_length; |
| 121 | if (l > 9) minlen = BROTLI_MAX(size_t, minlen, l - 9); |
| 122 | maxlen = BROTLI_MIN(size_t, matchlen, l - 2); |
| 123 | for (len = minlen; len <= maxlen; ++len) { |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 124 | AddMatch(id + kOmitLastNTransforms[l - len] * n, len, l, matches); |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 125 | has_found_match = BROTLI_TRUE; |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 126 | } |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 127 | if (matchlen < l || l + 6 >= max_length) { |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 128 | continue; |
| 129 | } |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 130 | s = &data[l]; |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 131 | /* Transforms "" + BROTLI_TRANSFORM_IDENTITY + <suffix> */ |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 132 | if (s[0] == ' ') { |
| 133 | AddMatch(id + n, l + 1, l, matches); |
| 134 | if (s[1] == 'a') { |
| 135 | if (s[2] == ' ') { |
| 136 | AddMatch(id + 28 * n, l + 3, l, matches); |
| 137 | } else if (s[2] == 's') { |
| 138 | if (s[3] == ' ') AddMatch(id + 46 * n, l + 4, l, matches); |
| 139 | } else if (s[2] == 't') { |
| 140 | if (s[3] == ' ') AddMatch(id + 60 * n, l + 4, l, matches); |
| 141 | } else if (s[2] == 'n') { |
| 142 | if (s[3] == 'd' && s[4] == ' ') { |
| 143 | AddMatch(id + 10 * n, l + 5, l, matches); |
| 144 | } |
| 145 | } |
| 146 | } else if (s[1] == 'b') { |
| 147 | if (s[2] == 'y' && s[3] == ' ') { |
| 148 | AddMatch(id + 38 * n, l + 4, l, matches); |
Eugene Kliuchnikov | 352b0b2 | 2016-06-03 11:19:23 +0200 | [diff] [blame] | 149 | } |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 150 | } else if (s[1] == 'i') { |
| 151 | if (s[2] == 'n') { |
| 152 | if (s[3] == ' ') AddMatch(id + 16 * n, l + 4, l, matches); |
| 153 | } else if (s[2] == 's') { |
| 154 | if (s[3] == ' ') AddMatch(id + 47 * n, l + 4, l, matches); |
| 155 | } |
| 156 | } else if (s[1] == 'f') { |
| 157 | if (s[2] == 'o') { |
| 158 | if (s[3] == 'r' && s[4] == ' ') { |
| 159 | AddMatch(id + 25 * n, l + 5, l, matches); |
| 160 | } |
| 161 | } else if (s[2] == 'r') { |
| 162 | if (s[3] == 'o' && s[4] == 'm' && s[5] == ' ') { |
| 163 | AddMatch(id + 37 * n, l + 6, l, matches); |
| 164 | } |
| 165 | } |
| 166 | } else if (s[1] == 'o') { |
| 167 | if (s[2] == 'f') { |
| 168 | if (s[3] == ' ') AddMatch(id + 8 * n, l + 4, l, matches); |
| 169 | } else if (s[2] == 'n') { |
| 170 | if (s[3] == ' ') AddMatch(id + 45 * n, l + 4, l, matches); |
| 171 | } |
| 172 | } else if (s[1] == 'n') { |
| 173 | if (s[2] == 'o' && s[3] == 't' && s[4] == ' ') { |
| 174 | AddMatch(id + 80 * n, l + 5, l, matches); |
| 175 | } |
| 176 | } else if (s[1] == 't') { |
| 177 | if (s[2] == 'h') { |
| 178 | if (s[3] == 'e') { |
| 179 | if (s[4] == ' ') AddMatch(id + 5 * n, l + 5, l, matches); |
| 180 | } else if (s[3] == 'a') { |
| 181 | if (s[4] == 't' && s[5] == ' ') { |
| 182 | AddMatch(id + 29 * n, l + 6, l, matches); |
| 183 | } |
| 184 | } |
| 185 | } else if (s[2] == 'o') { |
| 186 | if (s[3] == ' ') AddMatch(id + 17 * n, l + 4, l, matches); |
| 187 | } |
| 188 | } else if (s[1] == 'w') { |
| 189 | if (s[2] == 'i' && s[3] == 't' && s[4] == 'h' && s[5] == ' ') { |
| 190 | AddMatch(id + 35 * n, l + 6, l, matches); |
| 191 | } |
| 192 | } |
| 193 | } else if (s[0] == '"') { |
| 194 | AddMatch(id + 19 * n, l + 1, l, matches); |
| 195 | if (s[1] == '>') { |
| 196 | AddMatch(id + 21 * n, l + 2, l, matches); |
| 197 | } |
| 198 | } else if (s[0] == '.') { |
| 199 | AddMatch(id + 20 * n, l + 1, l, matches); |
| 200 | if (s[1] == ' ') { |
| 201 | AddMatch(id + 31 * n, l + 2, l, matches); |
| 202 | if (s[2] == 'T' && s[3] == 'h') { |
| 203 | if (s[4] == 'e') { |
| 204 | if (s[5] == ' ') AddMatch(id + 43 * n, l + 6, l, matches); |
| 205 | } else if (s[4] == 'i') { |
| 206 | if (s[5] == 's' && s[6] == ' ') { |
| 207 | AddMatch(id + 75 * n, l + 7, l, matches); |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | } else if (s[0] == ',') { |
| 213 | AddMatch(id + 76 * n, l + 1, l, matches); |
| 214 | if (s[1] == ' ') { |
| 215 | AddMatch(id + 14 * n, l + 2, l, matches); |
| 216 | } |
| 217 | } else if (s[0] == '\n') { |
| 218 | AddMatch(id + 22 * n, l + 1, l, matches); |
| 219 | if (s[1] == '\t') { |
| 220 | AddMatch(id + 50 * n, l + 2, l, matches); |
| 221 | } |
| 222 | } else if (s[0] == ']') { |
| 223 | AddMatch(id + 24 * n, l + 1, l, matches); |
| 224 | } else if (s[0] == '\'') { |
| 225 | AddMatch(id + 36 * n, l + 1, l, matches); |
| 226 | } else if (s[0] == ':') { |
| 227 | AddMatch(id + 51 * n, l + 1, l, matches); |
| 228 | } else if (s[0] == '(') { |
| 229 | AddMatch(id + 57 * n, l + 1, l, matches); |
| 230 | } else if (s[0] == '=') { |
| 231 | if (s[1] == '"') { |
| 232 | AddMatch(id + 70 * n, l + 2, l, matches); |
| 233 | } else if (s[1] == '\'') { |
| 234 | AddMatch(id + 86 * n, l + 2, l, matches); |
| 235 | } |
| 236 | } else if (s[0] == 'a') { |
| 237 | if (s[1] == 'l' && s[2] == ' ') { |
| 238 | AddMatch(id + 84 * n, l + 3, l, matches); |
| 239 | } |
| 240 | } else if (s[0] == 'e') { |
| 241 | if (s[1] == 'd') { |
| 242 | if (s[2] == ' ') AddMatch(id + 53 * n, l + 3, l, matches); |
| 243 | } else if (s[1] == 'r') { |
| 244 | if (s[2] == ' ') AddMatch(id + 82 * n, l + 3, l, matches); |
| 245 | } else if (s[1] == 's') { |
| 246 | if (s[2] == 't' && s[3] == ' ') { |
| 247 | AddMatch(id + 95 * n, l + 4, l, matches); |
| 248 | } |
| 249 | } |
| 250 | } else if (s[0] == 'f') { |
| 251 | if (s[1] == 'u' && s[2] == 'l' && s[3] == ' ') { |
| 252 | AddMatch(id + 90 * n, l + 4, l, matches); |
| 253 | } |
| 254 | } else if (s[0] == 'i') { |
| 255 | if (s[1] == 'v') { |
| 256 | if (s[2] == 'e' && s[3] == ' ') { |
Eugene Kliuchnikov | 352b0b2 | 2016-06-03 11:19:23 +0200 | [diff] [blame] | 257 | AddMatch(id + 92 * n, l + 4, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 258 | } |
| 259 | } else if (s[1] == 'z') { |
| 260 | if (s[2] == 'e' && s[3] == ' ') { |
| 261 | AddMatch(id + 100 * n, l + 4, l, matches); |
| 262 | } |
| 263 | } |
| 264 | } else if (s[0] == 'l') { |
| 265 | if (s[1] == 'e') { |
| 266 | if (s[2] == 's' && s[3] == 's' && s[4] == ' ') { |
| 267 | AddMatch(id + 93 * n, l + 5, l, matches); |
| 268 | } |
| 269 | } else if (s[1] == 'y') { |
| 270 | if (s[2] == ' ') AddMatch(id + 61 * n, l + 3, l, matches); |
| 271 | } |
| 272 | } else if (s[0] == 'o') { |
| 273 | if (s[1] == 'u' && s[2] == 's' && s[3] == ' ') { |
| 274 | AddMatch(id + 106 * n, l + 4, l, matches); |
| 275 | } |
| 276 | } |
| 277 | } else { |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 278 | /* Set is_all_caps=0 for BROTLI_TRANSFORM_UPPERCASE_FIRST and |
| 279 | is_all_caps=1 otherwise (BROTLI_TRANSFORM_UPPERCASE_ALL) |
| 280 | transform. */ |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 281 | const BROTLI_BOOL is_all_caps = |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 282 | TO_BROTLI_BOOL(w.transform != BROTLI_TRANSFORM_UPPERCASE_FIRST); |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 283 | const uint8_t* s; |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 284 | if (!IsMatch(dictionary->words, w, data, max_length)) { |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 285 | continue; |
| 286 | } |
Eugene Kliuchnikov | 352b0b2 | 2016-06-03 11:19:23 +0200 | [diff] [blame] | 287 | /* Transform "" + kUppercase{First,All} + "" */ |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 288 | AddMatch(id + (is_all_caps ? 44 : 9) * n, l, l, matches); |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 289 | has_found_match = BROTLI_TRUE; |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 290 | if (l + 1 >= max_length) { |
| 291 | continue; |
| 292 | } |
Eugene Kliuchnikov | 352b0b2 | 2016-06-03 11:19:23 +0200 | [diff] [blame] | 293 | /* Transforms "" + kUppercase{First,All} + <suffix> */ |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 294 | s = &data[l]; |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 295 | if (s[0] == ' ') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 296 | AddMatch(id + (is_all_caps ? 68 : 4) * n, l + 1, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 297 | } else if (s[0] == '"') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 298 | AddMatch(id + (is_all_caps ? 87 : 66) * n, l + 1, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 299 | if (s[1] == '>') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 300 | AddMatch(id + (is_all_caps ? 97 : 69) * n, l + 2, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 301 | } |
| 302 | } else if (s[0] == '.') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 303 | AddMatch(id + (is_all_caps ? 101 : 79) * n, l + 1, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 304 | if (s[1] == ' ') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 305 | AddMatch(id + (is_all_caps ? 114 : 88) * n, l + 2, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 306 | } |
| 307 | } else if (s[0] == ',') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 308 | AddMatch(id + (is_all_caps ? 112 : 99) * n, l + 1, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 309 | if (s[1] == ' ') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 310 | AddMatch(id + (is_all_caps ? 107 : 58) * n, l + 2, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 311 | } |
| 312 | } else if (s[0] == '\'') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 313 | AddMatch(id + (is_all_caps ? 94 : 74) * n, l + 1, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 314 | } else if (s[0] == '(') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 315 | AddMatch(id + (is_all_caps ? 113 : 78) * n, l + 1, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 316 | } else if (s[0] == '=') { |
| 317 | if (s[1] == '"') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 318 | AddMatch(id + (is_all_caps ? 105 : 104) * n, l + 2, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 319 | } else if (s[1] == '\'') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 320 | AddMatch(id + (is_all_caps ? 116 : 108) * n, l + 2, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | } |
Eugene Kliuchnikov | 352b0b2 | 2016-06-03 11:19:23 +0200 | [diff] [blame] | 326 | /* Transforms with prefixes " " and "." */ |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 327 | if (max_length >= 5 && (data[0] == ' ' || data[0] == '.')) { |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 328 | BROTLI_BOOL is_space = TO_BROTLI_BOOL(data[0] == ' '); |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 329 | size_t offset = dictionary->buckets[Hash(&data[1])]; |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 330 | BROTLI_BOOL end = !offset; |
| 331 | while (!end) { |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 332 | DictWord w = dictionary->dict_words[offset++]; |
Eugene Kliuchnikov | 8d3fdc1 | 2017-01-26 11:32:18 +0100 | [diff] [blame] | 333 | const size_t l = w.len & 0x1F; |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 334 | const size_t n = (size_t)1 << dictionary->words->size_bits_by_length[l]; |
Zoltan Szabadka | 8844b7f | 2016-01-07 16:27:49 +0100 | [diff] [blame] | 335 | const size_t id = w.idx; |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 336 | end = !!(w.len & 0x80); |
| 337 | w.len = (uint8_t)l; |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 338 | if (w.transform == 0) { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 339 | const uint8_t* s; |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 340 | if (!IsMatch(dictionary->words, w, &data[1], max_length - 1)) { |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 341 | continue; |
| 342 | } |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 343 | /* Transforms " " + BROTLI_TRANSFORM_IDENTITY + "" and |
| 344 | "." + BROTLI_TRANSFORM_IDENTITY + "" */ |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 345 | AddMatch(id + (is_space ? 6 : 32) * n, l + 1, l, matches); |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 346 | has_found_match = BROTLI_TRUE; |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 347 | if (l + 2 >= max_length) { |
| 348 | continue; |
| 349 | } |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 350 | /* Transforms " " + BROTLI_TRANSFORM_IDENTITY + <suffix> and |
| 351 | "." + BROTLI_TRANSFORM_IDENTITY + <suffix> |
Eugene Kliuchnikov | 352b0b2 | 2016-06-03 11:19:23 +0200 | [diff] [blame] | 352 | */ |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 353 | s = &data[l + 1]; |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 354 | if (s[0] == ' ') { |
| 355 | AddMatch(id + (is_space ? 2 : 77) * n, l + 2, l, matches); |
| 356 | } else if (s[0] == '(') { |
| 357 | AddMatch(id + (is_space ? 89 : 67) * n, l + 2, l, matches); |
| 358 | } else if (is_space) { |
| 359 | if (s[0] == ',') { |
| 360 | AddMatch(id + 103 * n, l + 2, l, matches); |
| 361 | if (s[1] == ' ') { |
| 362 | AddMatch(id + 33 * n, l + 3, l, matches); |
| 363 | } |
| 364 | } else if (s[0] == '.') { |
| 365 | AddMatch(id + 71 * n, l + 2, l, matches); |
| 366 | if (s[1] == ' ') { |
| 367 | AddMatch(id + 52 * n, l + 3, l, matches); |
| 368 | } |
| 369 | } else if (s[0] == '=') { |
| 370 | if (s[1] == '"') { |
| 371 | AddMatch(id + 81 * n, l + 3, l, matches); |
| 372 | } else if (s[1] == '\'') { |
| 373 | AddMatch(id + 98 * n, l + 3, l, matches); |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } else if (is_space) { |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 378 | /* Set is_all_caps=0 for BROTLI_TRANSFORM_UPPERCASE_FIRST and |
| 379 | is_all_caps=1 otherwise (BROTLI_TRANSFORM_UPPERCASE_ALL) |
| 380 | transform. */ |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 381 | const BROTLI_BOOL is_all_caps = |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 382 | TO_BROTLI_BOOL(w.transform != BROTLI_TRANSFORM_UPPERCASE_FIRST); |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 383 | const uint8_t* s; |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 384 | if (!IsMatch(dictionary->words, w, &data[1], max_length - 1)) { |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 385 | continue; |
| 386 | } |
Eugene Kliuchnikov | 352b0b2 | 2016-06-03 11:19:23 +0200 | [diff] [blame] | 387 | /* Transforms " " + kUppercase{First,All} + "" */ |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 388 | AddMatch(id + (is_all_caps ? 85 : 30) * n, l + 1, l, matches); |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 389 | has_found_match = BROTLI_TRUE; |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 390 | if (l + 2 >= max_length) { |
| 391 | continue; |
| 392 | } |
Eugene Kliuchnikov | 352b0b2 | 2016-06-03 11:19:23 +0200 | [diff] [blame] | 393 | /* Transforms " " + kUppercase{First,All} + <suffix> */ |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 394 | s = &data[l + 1]; |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 395 | if (s[0] == ' ') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 396 | AddMatch(id + (is_all_caps ? 83 : 15) * n, l + 2, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 397 | } else if (s[0] == ',') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 398 | if (!is_all_caps) { |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 399 | AddMatch(id + 109 * n, l + 2, l, matches); |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 400 | } |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 401 | if (s[1] == ' ') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 402 | AddMatch(id + (is_all_caps ? 111 : 65) * n, l + 3, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 403 | } |
| 404 | } else if (s[0] == '.') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 405 | AddMatch(id + (is_all_caps ? 115 : 96) * n, l + 2, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 406 | if (s[1] == ' ') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 407 | AddMatch(id + (is_all_caps ? 117 : 91) * n, l + 3, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 408 | } |
| 409 | } else if (s[0] == '=') { |
| 410 | if (s[1] == '"') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 411 | AddMatch(id + (is_all_caps ? 110 : 118) * n, l + 3, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 412 | } else if (s[1] == '\'') { |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 413 | AddMatch(id + (is_all_caps ? 119 : 120) * n, l + 3, l, matches); |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | } |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 419 | if (max_length >= 6) { |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 420 | /* Transforms with prefixes "e ", "s ", ", " and "\xC2\xA0" */ |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 421 | if ((data[1] == ' ' && |
| 422 | (data[0] == 'e' || data[0] == 's' || data[0] == ',')) || |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 423 | (data[0] == 0xC2 && data[1] == 0xA0)) { |
| 424 | size_t offset = dictionary->buckets[Hash(&data[2])]; |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 425 | BROTLI_BOOL end = !offset; |
| 426 | while (!end) { |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 427 | DictWord w = dictionary->dict_words[offset++]; |
Eugene Kliuchnikov | 8d3fdc1 | 2017-01-26 11:32:18 +0100 | [diff] [blame] | 428 | const size_t l = w.len & 0x1F; |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 429 | const size_t n = (size_t)1 << dictionary->words->size_bits_by_length[l]; |
Zoltan Szabadka | 8844b7f | 2016-01-07 16:27:49 +0100 | [diff] [blame] | 430 | const size_t id = w.idx; |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 431 | end = !!(w.len & 0x80); |
| 432 | w.len = (uint8_t)l; |
Eugene Kliuchnikov | cdca91b | 2017-03-06 14:22:45 +0100 | [diff] [blame] | 433 | if (w.transform == 0 && |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 434 | IsMatch(dictionary->words, w, &data[2], max_length - 2)) { |
| 435 | if (data[0] == 0xC2) { |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 436 | AddMatch(id + 102 * n, l + 2, l, matches); |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 437 | has_found_match = BROTLI_TRUE; |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 438 | } else if (l + 2 < max_length && data[l + 2] == ' ') { |
Zoltan Szabadka | 8844b7f | 2016-01-07 16:27:49 +0100 | [diff] [blame] | 439 | size_t t = data[0] == 'e' ? 18 : (data[0] == 's' ? 7 : 13); |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 440 | AddMatch(id + t * n, l + 3, l, matches); |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 441 | has_found_match = BROTLI_TRUE; |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 442 | } |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | } |
| 446 | } |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 447 | if (max_length >= 9) { |
Eugene Kliuchnikov | 352b0b2 | 2016-06-03 11:19:23 +0200 | [diff] [blame] | 448 | /* Transforms with prefixes " the " and ".com/" */ |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 449 | if ((data[0] == ' ' && data[1] == 't' && data[2] == 'h' && |
| 450 | data[3] == 'e' && data[4] == ' ') || |
| 451 | (data[0] == '.' && data[1] == 'c' && data[2] == 'o' && |
| 452 | data[3] == 'm' && data[4] == '/')) { |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 453 | size_t offset = dictionary->buckets[Hash(&data[5])]; |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 454 | BROTLI_BOOL end = !offset; |
| 455 | while (!end) { |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 456 | DictWord w = dictionary->dict_words[offset++]; |
Eugene Kliuchnikov | 8d3fdc1 | 2017-01-26 11:32:18 +0100 | [diff] [blame] | 457 | const size_t l = w.len & 0x1F; |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 458 | const size_t n = (size_t)1 << dictionary->words->size_bits_by_length[l]; |
Zoltan Szabadka | 8844b7f | 2016-01-07 16:27:49 +0100 | [diff] [blame] | 459 | const size_t id = w.idx; |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 460 | end = !!(w.len & 0x80); |
| 461 | w.len = (uint8_t)l; |
Eugene Kliuchnikov | cdca91b | 2017-03-06 14:22:45 +0100 | [diff] [blame] | 462 | if (w.transform == 0 && |
Eugene Kliuchnikov | 35e69fc | 2018-02-26 09:04:36 -0500 | [diff] [blame^] | 463 | IsMatch(dictionary->words, w, &data[5], max_length - 5)) { |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 464 | AddMatch(id + (data[0] == ' ' ? 41 : 72) * n, l + 5, l, matches); |
Eugene Kliuchnikov | 2048189 | 2016-07-26 14:41:59 +0200 | [diff] [blame] | 465 | has_found_match = BROTLI_TRUE; |
Lode Vandevenne | 17ed258 | 2015-08-10 13:13:58 +0200 | [diff] [blame] | 466 | if (l + 5 < max_length) { |
| 467 | const uint8_t* s = &data[l + 5]; |
| 468 | if (data[0] == ' ') { |
| 469 | if (l + 8 < max_length && |
| 470 | s[0] == ' ' && s[1] == 'o' && s[2] == 'f' && s[3] == ' ') { |
| 471 | AddMatch(id + 62 * n, l + 9, l, matches); |
| 472 | if (l + 12 < max_length && |
| 473 | s[4] == 't' && s[5] == 'h' && s[6] == 'e' && s[7] == ' ') { |
| 474 | AddMatch(id + 73 * n, l + 13, l, matches); |
| 475 | } |
| 476 | } |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | } |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 483 | return has_found_match; |
Zoltan Szabadka | 6609883 | 2015-06-12 16:45:17 +0200 | [diff] [blame] | 484 | } |
| 485 | |
Eugene Kliuchnikov | b972c67 | 2016-06-13 11:01:04 +0200 | [diff] [blame] | 486 | #if defined(__cplusplus) || defined(c_plusplus) |
| 487 | } /* extern "C" */ |
| 488 | #endif |