Debian Codegraph @

lib/snip.c

raw symbols SCIP
1 /*
2 Copyright (C) 2009-2014 Brazil
3 Copyright (C) 2021-2023 Sutou Kouhei <[email protected]>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "grn.h"cxx . . $ `<file>/lib/grn.h`/
21 #include <string.h>
22 #include <stddef.h>
23 #include "grn_snip.h"cxx . . $ `<file>/lib/grn_snip.h`/
24 #include "grn_ctx.h"cxx . . $ `<file>/lib/grn_ctx.h`/
25
26 #if !defined MAXcxx . . $ `<external>/1231830743887005719/param.h:103:9`!
27 # define MAX(a, b) ((a) > (b) ? (a) : (b))
28 #endif
29
30 #if !defined MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!
31 # define MIN(a, b) ((a) < (b) ? (a) : (b))
32 #endif
33
34 static int
35 grn_bm_check_euccxx . . $ grn_bm_check_euc(22502bda773498f8).(const unsigned char *x, const size_t y)
36 {
37 const unsigned char *p;
38 for (p = x + y - 1; p >= x && *p >= 0x80U; p--)
39 ;
40 return (int)((x + y - p) & 1);
41 }
42
43 static int
44 grn_bm_check_sjiscxx . . $ grn_bm_check_sjis(22502bda773498f8).(const unsigned char *x, const size_t y)
45 {
46 const unsigned char *p;
47 for (p = x + y - 1; p >= x; p--)
48 if ((*p < 0x81U) || (*p > 0x9fU && *p < 0xe0U) || (*p > 0xfcU)) break;
49 return (int)((x + y - p) & 1);
50 }
51
52 /*
53 static void
54 grn_bm_suffixes(const unsigned char *x, size_t m, size_t *suff)
55 {
56 size_t f, g;
57 intptr_t i;
58 f = 0;
59 suff[m - 1] = m;
60 g = m - 1;
61 for (i = m - 2; i >= 0; --i) {
62 if (i > (intptr_t) g && suff[i + m - 1 - f] < i - g)
63 suff[i] = suff[i + m - 1 - f];
64 else {
65 if (i < (intptr_t) g)
66 g = i;
67 f = i;
68 while (g > 0 && x[g] == x[g + m - 1 - f])
69 --g;
70 suff[i] = f - g;
71 }
72 }
73 }
74 */
75
76 static void
77 grn_bm_preBmBccxx . . $ grn_bm_preBmBc(4ec2f154020347b2).(const unsigned char *x, size_t m, size_t *bmBc)
78 {
79 size_t i;
80 for (i = 0; i < ASIZEcxx . . $ `lib/grn_snip.h:27:9`!; ++i) {
81 bmBc[i] = m;
82 }
83 for (i = 0; i < m - 1; ++i) {
84 bmBc[(unsigned int)x[i]] = m - (i + 1);
85 }
86 }
87
88 #define GRN_BM_COMPAREcxx . . $ `lib/snip.c:88:9`! \
89 do { \
90 if (string_checks[found]) { \
91 size_t offset = cond->last_offset; \
92 ptrdiff_t found_alpha_head = cond->found_alpha_head; \
93 /* calc real offset */ \
94 for (i = cond->last_found; i < found; i++) { \
95 if (string_checks[i] > 0) { \
96 found_alpha_head = i; \
97 offset += (size_t)(string_checks[i]); \
98 } \
99 } \
100 /* if real offset is in a character, move it the head of the character \
101 */ \
102 if (string_checks[found] < 0) { \
103 offset -= (size_t)(string_checks[found_alpha_head]); \
104 cond->last_found = found_alpha_head; \
105 } else { \
106 cond->last_found = found; \
107 } \
108 cond->start_offset = cond->last_offset = offset; \
109 if (flags & GRN_SNIP_SKIP_LEADING_SPACEScxx . . $ `include/groonga/groonga.h:2306:9`!) { \
110 while (cond->start_offset < string_original_length_in_bytes && \
111 (i = grn_isspace(string_original + cond->start_offset, \
112 string_encoding))) { \
113 cond->start_offset += (size_t)(i); \
114 } \
115 } \
116 for (i = cond->last_found; i < found + m; i++) { \
117 if (string_checks[i] > 0) { \
118 offset += (size_t)(string_checks[i]); \
119 } \
120 } \
121 cond->end_offset = offset; \
122 cond->found = found + shift; \
123 cond->found_alpha_head = found_alpha_head; \
124 /* printf("bm: cond:%p found:%zd last_found:%zd st_off:%zd \
125 * ed_off:%zd\n", cond, \
126 * cond->found,cond->last_found,cond->start_offset,cond->end_offset); */ \
127 return; \
128 } \
129 } while (0)
130
131 #define GRN_BM_BM_COMPAREcxx . . $ `lib/snip.c:131:9`! \
132 do { \
133 if (p[-2] == ck) { \
134 for (i = 3; i <= m && p[-(intptr_t)i] == cp[-(intptr_t)i]; ++i) { \
135 } \
136 if (i > m) { \
137 found = p - y - m; \
138 GRN_BM_COMPAREcxx . . $ `lib/snip.c:88:9`!; \
139 } \
140 } \
141 } while (0)
142
143 void
144 grn_bm_tunedbmcxx . . $ grn_bm_tunedbm(a2637678f71cc9af).(grn_ctxcxx . . $ grn_ctx# *ctx, snip_condcxx . . $ snip_cond# *cond, grn_objcxx . . $ grn_obj# *string, int flags)
145 {
146 register unsigned char *limit, ck;
147 register const unsigned char *p, *cp;
148 register size_t *bmBc, delta1;
149 register ptrdiff_t i;
150
151 const unsigned char *x;
152 unsigned char *y;
153 ptrdiff_t shift;
154 ptrdiff_t found;
155
156 const char *string_original;
157 unsigned int string_original_length_in_bytes;
158 const short *string_checks;
159 grn_encodingcxx . . $ grn_encoding# string_encoding;
160 const char *string_norm, *keyword_norm;
161 unsigned int n, m;
162
163 grn_string_get_originalcxx . . $ grn_string_get_original(87996916c40b1978).(ctx,
164 string,
165 &string_original,
166 &string_original_length_in_bytes);
167 string_checks = grn_string_get_checkscxx . . $ grn_string_get_checks(392ec27081c21988).(ctx, string);
168 string_encoding = grn_string_get_encodingcxx . . $ grn_string_get_encoding(a50aff468d99e115).(ctx, string);
169 grn_string_get_normalizedcxx . . $ grn_string_get_normalized(fcb0da4d05783f05).(ctx, string, &string_norm, &n, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
170 grn_string_get_normalizedcxx . . $ grn_string_get_normalized(fcb0da4d05783f05).(ctx, cond->keywordcxx . . $ _snip_cond#keyword., &keyword_norm, &m, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
171
172 y = (unsigned char *)string_norm;
173 if (m == 1) {
174 if (n > cond->foundcxx . . $ _snip_cond#found.) {
175 shift = 1;
176 p = memchrcxx . . $ `<external>/13506128340496143423/string.h:121:11`!(y + cond->found, keyword_norm[0], (size_t)(n - cond->found));
177 if (p != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
178 found = p - y;
179 GRN_BM_COMPAREcxx . . $ `lib/snip.c:88:9`!;
180 }
181 }
182 cond->stopflagcxx . . $ _snip_cond#stopflag. = SNIPCOND_STOPcxx . . $ `lib/grn_snip.h:37:9`!;
183 return;
184 }
185
186 x = (unsigned char *)keyword_norm;
187 bmBc = cond->bmBccxx . . $ _snip_cond#bmBc.;
188 shift = cond->shiftcxx . . $ _snip_cond#shift.;
189
190 /* Restart */
191 p = y + m + cond->foundcxx . . $ _snip_cond#found.;
192 cp = x + m;
193 ck = cp[-2];
194
195 /* 12 means 1(initial offset) + 10 (in loop) + 1 (shift) */
196 if (n - cond->foundcxx . . $ _snip_cond#found. > 12 * m) {
197 limit = y + n - 11 * m;
198 while (p <= limit) {
199 p += bmBc[p[-1]];
200 if (!(delta1 = bmBc[p[-1]])) {
201 goto check;
202 }
203 p += delta1;
204 p += bmBc[p[-1]];
205 p += bmBc[p[-1]];
206 if (!(delta1 = bmBc[p[-1]])) {
207 goto check;
208 }
209 p += delta1;
210 p += bmBc[p[-1]];
211 p += bmBc[p[-1]];
212 if (!(delta1 = bmBc[p[-1]])) {
213 goto check;
214 }
215 p += delta1;
216 p += bmBc[p[-1]];
217 p += bmBc[p[-1]];
218 continue;
219 check:
220 GRN_BM_BM_COMPAREcxx . . $ `lib/snip.c:131:9`!;
221 p += shift;
222 }
223 }
224 /* limit check + search */
225 limit = y + n;
226 while (p <= limit) {
227 if (!(delta1 = bmBc[p[-1]])) {
228 GRN_BM_BM_COMPAREcxx . . $ `lib/snip.c:131:9`!;
229 p += shift;
230 }
231 p += delta1;
232 }
233 cond->stopflagcxx . . $ _snip_cond#stopflag. = SNIPCOND_STOPcxx . . $ `lib/grn_snip.h:37:9`!;
234 }
235
236 static size_t
237 count_mapped_charscxx . . $ count_mapped_chars(335c1dc86f5c867f).(const char *str, const char *end)
238 {
239 const char *p;
240 size_t dl;
241
242 dl = 0;
243 for (p = str; p != end; p++) {
244 switch (*p) {
245 case '<':
246 case '>':
247 dl += 4; /* &lt; or &gt; */
248 break;
249 case '&':
250 dl += 5; /* &amp; */
251 break;
252 case '"':
253 dl += 6; /* &quot; */
254 break;
255 default:
256 dl++;
257 break;
258 }
259 }
260 return dl;
261 }
262
263 grn_rccxx . . $ grn_rc#
264 grn_snip_cond_closecxx . . $ grn_snip_cond_close(14d09e9a60b32ef0).(grn_ctxcxx . . $ grn_ctx# *ctx, snip_condcxx . . $ snip_cond# *cond)
265 {
266 if (!cond) {
267 return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.;
268 }
269 if (cond->keywordcxx . . $ _snip_cond#keyword.) {
270 grn_obj_closecxx . . $ grn_obj_close(4865d068a46d0f83).(ctx, cond->keywordcxx . . $ _snip_cond#keyword.);
271 }
272 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
273 }
274
275 static grn_rccxx . . $ grn_rc#
276 grn_snip_cond_initcxx . . $ grn_snip_cond_init(ccbffc669a2d1c19).(grn_ctxcxx . . $ grn_ctx# *ctx,
277 snip_condcxx . . $ snip_cond# *sc,
278 const char *keyword,
279 unsigned int keyword_len,
280 grn_encodingcxx . . $ grn_encoding# enc,
281 grn_objcxx . . $ grn_obj# *normalizer,
282 int flags)
283 {
284 const char *norm;
285 unsigned int norm_blen;
286 int f = GRN_STR_REMOVEBLANKcxx . . $ `include/groonga/string.h:40:9`!;
287 memsetcxx . . $ memset(d1de1e4fb215f1c6).(sc, 0, sizeof(snip_condcxx . . $ snip_cond#));
288 if (!(sc->keywordcxx . . $ _snip_cond#keyword. =
289 grn_string_opencxx . . $ grn_string_open(e91f62a415156742).(ctx, keyword, keyword_len, normalizer, f))) {
290 GRN_LOGcxx . . $ `include/groonga/groonga.h:2493:9`!(ctx, GRN_LOG_ALERT, "grn_string_open on snip_cond_init failed!");
291 return GRN_NO_MEMORY_AVAILABLEcxx . . $ GRN_NO_MEMORY_AVAILABLE.;
292 }
293 grn_string_get_normalizedcxx . . $ grn_string_get_normalized(fcb0da4d05783f05).(ctx, sc->keywordcxx . . $ _snip_cond#keyword., &norm, &norm_blen, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
294 if (!norm_blen) {
295 grn_snip_cond_closecxx . . $ grn_snip_cond_close(14d09e9a60b32ef0).(ctx, sc);
296 return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.;
297 }
298 if (norm_blen != 1) {
299 grn_bm_preBmBccxx . . $ grn_bm_preBmBc(4ec2f154020347b2).((unsigned char *)norm, norm_blen, sc->bmBccxx . . $ _snip_cond#bmBc.);
300 sc->shiftcxx . . $ _snip_cond#shift. = sc->bmBccxx . . $ _snip_cond#bmBc.[(unsigned char)norm[norm_blen - 1]];
301 sc->bmBccxx . . $ _snip_cond#bmBc.[(unsigned char)norm[norm_blen - 1]] = 0;
302 }
303 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
304 }
305
306 static void
307 grn_snip_cond_reinitcxx . . $ grn_snip_cond_reinit(49091ad9ba26c801).(snip_condcxx . . $ snip_cond# *cond)
308 {
309 cond->foundcxx . . $ _snip_cond#found. = 0;
310 cond->last_foundcxx . . $ _snip_cond#last_found. = 0;
311 cond->last_offsetcxx . . $ _snip_cond#last_offset. = 0;
312 cond->start_offsetcxx . . $ _snip_cond#start_offset. = 0;
313 cond->end_offsetcxx . . $ _snip_cond#end_offset. = 0;
314
315 cond->countcxx . . $ _snip_cond#count. = 0;
316 cond->stopflagcxx . . $ _snip_cond#stopflag. = SNIPCOND_NONSTOPcxx . . $ `lib/grn_snip.h:36:9`!;
317 }
318
319 static inline char *
320 grn_snip_strndupcxx . . $ grn_snip_strndup(5bbb7a0ed225bf59).(grn_ctxcxx . . $ grn_ctx# *ctx, const char *string, size_t string_len)
321 {
322 char *copied_string;
323
324 copied_string = GRN_MALLOCcxx . . $ `lib/grn_alloc.h:41:9`!(string_len + 1);
325 if (!copied_string) {
326 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
327 }
328 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(copied_string, string, string_len);
329 copied_string[string_len] = '\0'; /* not required, but for ql use */
330 return copied_string;
331 }
332
333 static inline grn_rccxx . . $ grn_rc#
334 grn_snip_cond_set_tagcxx . . $ grn_snip_cond_set_tag(4f25aab6afebd91b).(grn_ctxcxx . . $ grn_ctx# *ctx,
335 const char **dest_tag,
336 size_t *dest_tag_len,
337 const char *tag,
338 size_t tag_len,
339 const char *default_tag,
340 size_t default_tag_len,
341 int copy_tag)
342 {
343 if (tag) {
344 if (copy_tag) {
345 char *copied_tag;
346 copied_tag = grn_snip_strndupcxx . . $ grn_snip_strndup(5bbb7a0ed225bf59).(ctx, tag, tag_len);
347 if (!copied_tag) {
348 return GRN_NO_MEMORY_AVAILABLEcxx . . $ GRN_NO_MEMORY_AVAILABLE.;
349 }
350 *dest_tag = copied_tag;
351 } else {
352 *dest_tag = tag;
353 }
354 *dest_tag_len = tag_len;
355 } else {
356 *dest_tag = default_tag;
357 *dest_tag_len = default_tag_len;
358 }
359 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
360 }
361
362 grn_rccxx . . $ grn_rc#
363 grn_snip_set_normalizercxx . . $ grn_snip_set_normalizer(d825b4ed5bf12304).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *snip, grn_objcxx . . $ grn_obj# *normalizer)
364 {
365 grn_snipcxx . . $ grn_snip# *snip_;
366 if (!snip) {
367 return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.;
368 }
369
370 snip_ = (grn_snipcxx . . $ grn_snip# *)snip;
371 if (snip_->normalizercxx . . $ _grn_snip#normalizer. != normalizer) {
372 if (snip_->normalizercxx . . $ _grn_snip#normalizer. && snip_->normalizercxx . . $ _grn_snip#normalizer. != GRN_NORMALIZER_AUTOcxx . . $ `include/groonga/string.h:57:9`!) {
373 grn_obj_unrefcxx . . $ grn_obj_unref(cda3a5f3c2e53c6b).(ctx, snip_->normalizercxx . . $ _grn_snip#normalizer.);
374 }
375 snip_->normalizercxx . . $ _grn_snip#normalizer. = normalizer;
376 if (snip_->normalizercxx . . $ _grn_snip#normalizer. && snip_->normalizercxx . . $ _grn_snip#normalizer. != GRN_NORMALIZER_AUTOcxx . . $ `include/groonga/string.h:57:9`!) {
377 grn_obj_refercxx . . $ grn_obj_refer(4865d068a46d0f83).(ctx, snip_->normalizercxx . . $ _grn_snip#normalizer.);
378 }
379 }
380 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
381 }
382
383 grn_objcxx . . $ grn_obj# *
384 grn_snip_get_normalizercxx . . $ grn_snip_get_normalizer(e9f40e4080908c1e).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *snip)
385 {
386 grn_snipcxx . . $ grn_snip# *snip_;
387
388 if (!snip) {
389 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
390 }
391
392 snip_ = (grn_snipcxx . . $ grn_snip# *)snip;
393 return snip_->normalizercxx . . $ _grn_snip#normalizer.;
394 }
395
396 grn_rccxx . . $ grn_rc#
397 grn_snip_set_normalizerscxx . . $ grn_snip_set_normalizers(d825b4ed5bf12304).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *snip, grn_objcxx . . $ grn_obj# *normalizers)
398 {
399 grn_snipcxx . . $ grn_snip# *snip_;
400 if (!snip) {
401 return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.;
402 }
403
404 if (!grn_obj_is_text_family_bulkcxx . . $ grn_obj_is_text_family_bulk(a5760e5c319a06ee).(ctx, normalizers)) {
405 return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.;
406 }
407
408 snip_ = (grn_snipcxx . . $ grn_snip# *)snip;
409 if (GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(normalizers) == 0) {
410 GRN_BULK_REWINDcxx . . $ `include/groonga/groonga.h:2599:9`!(&(snip_->normalizers));
411 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
412 }
413
414 if (!snip_->lexiconcxx . . $ _grn_snip#lexicon.) {
415 /* This is only used for passing normalizer options to grn_string. */
416 snip_->lexiconcxx . . $ _grn_snip#lexicon. = grn_table_createcxx . . $ grn_table_create(51df5019e8d3bdc1).(ctx,
417 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
418 0,
419 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
420 GRN_OBJ_TABLE_HASH_KEYcxx . . $ `include/groonga/groonga.h:688:9`!,
421 grn_ctx_atcxx . . $ grn_ctx_at(ac4544c8400954c9).(ctx, GRN_DB_SHORT_TEXTcxx . . $ GRN_DB_SHORT_TEXT.),
422 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
423 if (!snip_->lexiconcxx . . $ _grn_snip#lexicon.) {
424 return ctx->rccxx . . $ _grn_ctx#rc.;
425 }
426 }
427 grn_obj_set_infocxx . . $ grn_obj_set_info(1c4fe9650683f16e).(ctx, snip_->lexiconcxx . . $ _grn_snip#lexicon., GRN_INFO_NORMALIZERScxx . . $ GRN_INFO_NORMALIZERS., normalizers);
428 if (ctx->rccxx . . $ _grn_ctx#rc. == GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
429 GRN_TEXT_SETcxx . . $ `include/groonga/groonga.h:2761:9`!(ctx,
430 &(snip_->normalizers),
431 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(normalizers),
432 GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(normalizers));
433 }
434 return ctx->rccxx . . $ _grn_ctx#rc.;
435 }
436
437 grn_objcxx . . $ grn_obj# *
438 grn_snip_get_normalizerscxx . . $ grn_snip_get_normalizers(e9f40e4080908c1e).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *snip)
439 {
440 grn_snipcxx . . $ grn_snip# *snip_;
441
442 if (!snip) {
443 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
444 }
445
446 snip_ = (grn_snipcxx . . $ grn_snip# *)snip;
447 return &(snip_->normalizerscxx . . $ _grn_snip#normalizers.);
448 }
449
450 grn_rccxx . . $ grn_rc#
451 grn_snip_set_delimiter_regexpcxx . . $ grn_snip_set_delimiter_regexp(376b059b992fb10f).(grn_ctxcxx . . $ grn_ctx# *ctx,
452 grn_objcxx . . $ grn_obj# *snip,
453 const char *pattern,
454 int pattern_length)
455 {
456 const char *tag = "[snip][delimiter-regexp][set]";
457
458 if (!snip) {
459 return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.;
460 }
461
462 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
463 #ifdef GRN_SUPPORT_REGEXPcxx . . $ `lib/grn.h:734:11`!
464 grn_snipcxx . . $ grn_snip# *snip_ = (grn_snipcxx . . $ grn_snip# *)snip;
465 if (snip_->delimiter_regexcxx . . $ _grn_snip#delimiter_regex.) {
466 onig_freecxx . . $ onig_free(b1814a8fd6af504b).(snip_->delimiter_regexcxx . . $ _grn_snip#delimiter_regex.);
467 }
468 if (snip_->delimiter_patterncxx . . $ _grn_snip#delimiter_pattern.) {
469 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(snip_->delimiter_pattern);
470 }
471 if (pattern) {
472 if (pattern_length < 0) {
473 snip_->delimiter_pattern_lengthcxx . . $ _grn_snip#delimiter_pattern_length. = strlencxx . . $ strlen(751346f8406fd082).(pattern);
474 } else {
475 snip_->delimiter_pattern_lengthcxx . . $ _grn_snip#delimiter_pattern_length. = (size_t)pattern_length;
476 }
477 snip_->delimiter_patterncxx . . $ _grn_snip#delimiter_pattern. =
478 grn_snip_strndupcxx . . $ grn_snip_strndup(5bbb7a0ed225bf59).(ctx, pattern, snip_->delimiter_pattern_lengthcxx . . $ _grn_snip#delimiter_pattern_length.);
479 if (snip_->delimiter_patterncxx . . $ _grn_snip#delimiter_pattern.) {
480 snip_->delimiter_regexcxx . . $ _grn_snip#delimiter_regex. = grn_onigmo_newcxx . . $ grn_onigmo_new(5d4bcbb55fe07878).(ctx,
481 pattern,
482 snip_->delimiter_pattern_lengthcxx . . $ _grn_snip#delimiter_pattern_length.,
483 GRN_ONIGMO_OPTION_DEFAULTcxx . . $ `lib/grn_onigmo.h:33:9`!,
484 GRN_ONIGMO_SYNTAX_DEFAULTcxx . . $ `lib/grn_onigmo.h:37:9`!,
485 tag);
486 }
487 } else {
488 snip_->delimiter_regexcxx . . $ _grn_snip#delimiter_regex. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
489 snip_->delimiter_patterncxx . . $ _grn_snip#delimiter_pattern. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
490 }
491 #else
492 ERR(GRN_FUNCTION_NOT_IMPLEMENTED, "%s Onigmo isn't enabled", tag);
493 #endif
494 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
495 }
496
497 const char *
498 grn_snip_get_delimiter_regexpcxx . . $ grn_snip_get_delimiter_regexp(b7bca21e38c64932).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *snip, size_t *length)
499 {
500 grn_snipcxx . . $ grn_snip# *snip_;
501
502 if (!snip) {
503 if (length) {
504 *length = 0;
505 }
506 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
507 }
508
509 snip_ = (grn_snipcxx . . $ grn_snip# *)snip;
510 if (length) {
511 *length = snip_->delimiter_pattern_lengthcxx . . $ _grn_snip#delimiter_pattern_length.;
512 }
513 return snip_->delimiter_patterncxx . . $ _grn_snip#delimiter_pattern.;
514 }
515
516 static grn_rccxx . . $ grn_rc#
517 grn_snip_expand_condcxx . . $ grn_snip_expand_cond(5150f6f5175b280c).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_snipcxx . . $ grn_snip# *snip)
518 {
519 size_t new_cond_capacity = snip->cond_capacitycxx . . $ _grn_snip#cond_capacity. * 2;
520 size_t new_cond_size = sizeof(snip_condcxx . . $ snip_cond#) * new_cond_capacity;
521 snip_condcxx . . $ snip_cond# *new_cond = (snip_condcxx . . $ snip_cond# *)GRN_REALLOCcxx . . $ `lib/grn_alloc.h:43:9`!(snip->cond, new_cond_size);
522 if (!new_cond) {
523 return ctx->rccxx . . $ _grn_ctx#rc.;
524 }
525 snip->condcxx . . $ _grn_snip#cond. = new_cond;
526 snip->cond_capacitycxx . . $ _grn_snip#cond_capacity. = new_cond_capacity;
527 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
528 }
529
530 grn_rccxx . . $ grn_rc#
531 grn_snip_add_condcxx . . $ grn_snip_add_cond(ee5560011b897937).(grn_ctxcxx . . $ grn_ctx# *ctx,
532 grn_objcxx . . $ grn_obj# *snip,
533 const char *keyword,
534 unsigned int keyword_len,
535 const char *opentag,
536 unsigned int opentag_len,
537 const char *closetag,
538 unsigned int closetag_len)
539 {
540 grn_rccxx . . $ grn_rc# rc;
541 int copy_tag;
542 snip_condcxx . . $ snip_cond# *cond;
543 unsigned int norm_blen;
544 grn_snipcxx . . $ grn_snip# *snip_;
545
546 snip_ = (grn_snipcxx . . $ grn_snip# *)snip;
547 if (!snip_ || !keyword || !keyword_len) {
548 return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.;
549 }
550
551 if (snip_->cond_lencxx . . $ _grn_snip#cond_len. >= snip_->cond_capacitycxx . . $ _grn_snip#cond_capacity.) {
552 rc = grn_snip_expand_condcxx . . $ grn_snip_expand_cond(5150f6f5175b280c).(ctx, snip_);
553 if (rc) {
554 return rc;
555 }
556 }
557
558 cond = snip_->condcxx . . $ _grn_snip#cond. + snip_->cond_lencxx . . $ _grn_snip#cond_len.;
559 rc = grn_snip_cond_initcxx . . $ grn_snip_cond_init(ccbffc669a2d1c19).(ctx,
560 cond,
561 keyword,
562 keyword_len,
563 snip_->encodingcxx . . $ _grn_snip#encoding.,
564 (GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&(snip_->normalizers)) > 0)
565 ? snip_->lexiconcxx . . $ _grn_snip#lexicon.
566 : snip_->normalizercxx . . $ _grn_snip#normalizer.,
567 snip_->flagscxx . . $ _grn_snip#flags.);
568 if (rc) {
569 return rc;
570 }
571 grn_string_get_normalizedcxx . . $ grn_string_get_normalized(fcb0da4d05783f05).(ctx, cond->keywordcxx . . $ _snip_cond#keyword., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &norm_blen, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
572 if (norm_blen > snip_->widthcxx . . $ _grn_snip#width.) {
573 grn_snip_cond_closecxx . . $ grn_snip_cond_close(14d09e9a60b32ef0).(ctx, cond);
574 return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.;
575 }
576
577 copy_tag = snip_->flagscxx . . $ _grn_snip#flags. & GRN_SNIP_COPY_TAGcxx . . $ `include/groonga/groonga.h:2305:9`!;
578 rc = grn_snip_cond_set_tagcxx . . $ grn_snip_cond_set_tag(4f25aab6afebd91b).(ctx,
579 &(cond->opentagcxx . . $ _snip_cond#opentag.),
580 &(cond->opentag_lencxx . . $ _snip_cond#opentag_len.),
581 opentag,
582 opentag_len,
583 snip_->defaultopentagcxx . . $ _grn_snip#defaultopentag.,
584 snip_->defaultopentag_lencxx . . $ _grn_snip#defaultopentag_len.,
585 copy_tag);
586 if (rc) {
587 grn_snip_cond_closecxx . . $ grn_snip_cond_close(14d09e9a60b32ef0).(ctx, cond);
588 return rc;
589 }
590
591 rc = grn_snip_cond_set_tagcxx . . $ grn_snip_cond_set_tag(4f25aab6afebd91b).(ctx,
592 &(cond->closetagcxx . . $ _snip_cond#closetag.),
593 &(cond->closetag_lencxx . . $ _snip_cond#closetag_len.),
594 closetag,
595 closetag_len,
596 snip_->defaultclosetagcxx . . $ _grn_snip#defaultclosetag.,
597 snip_->defaultclosetag_lencxx . . $ _grn_snip#defaultclosetag_len.,
598 copy_tag);
599 if (rc) {
600 if (opentag && copy_tag) {
601 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!((void *)cond->opentag);
602 }
603 grn_snip_cond_closecxx . . $ grn_snip_cond_close(14d09e9a60b32ef0).(ctx, cond);
604 return rc;
605 }
606
607 snip_->cond_lencxx . . $ _grn_snip#cond_len.++;
608 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
609 }
610
611 static size_t
612 grn_snip_find_firstbytecxx . . $ grn_snip_find_firstbyte(3c714cfd8f3d9b8e).(const char *string,
613 grn_encodingcxx . . $ grn_encoding# encoding,
614 size_t offset,
615 ssize_tcxx . . $ ssize_t# doffset)
616 {
617 switch (encoding) {
618 case GRN_ENC_EUC_JPcxx . . $ GRN_ENC_EUC_JP.:
619 while (!(grn_bm_check_euccxx . . $ grn_bm_check_euc(22502bda773498f8).((unsigned char *)string, offset)))
620 offset = (size_t)((ssize_tcxx . . $ ssize_t#)offset + doffset);
621 break;
622 case GRN_ENC_SJIScxx . . $ GRN_ENC_SJIS.:
623 if (!(grn_bm_check_sjiscxx . . $ grn_bm_check_sjis(22502bda773498f8).((unsigned char *)string, offset)))
624 offset = (size_t)((ssize_tcxx . . $ ssize_t#)offset + doffset);
625 break;
626 case GRN_ENC_UTF8cxx . . $ GRN_ENC_UTF8.:
627 while ((signed char)string[offset] <= (signed char)0xc0)
628 offset = (size_t)((ssize_tcxx . . $ ssize_t#)offset + doffset);
629 break;
630 default:
631 break;
632 }
633 return offset;
634 }
635
636 static inline grn_rccxx . . $ grn_rc#
637 grn_snip_set_default_tagcxx . . $ grn_snip_set_default_tag(b4f7644ba878ea1e).(grn_ctxcxx . . $ grn_ctx# *ctx,
638 const char **dest_tag,
639 size_t *dest_tag_len,
640 const char *tag,
641 unsigned int tag_len,
642 int copy_tag)
643 {
644 if (copy_tag && tag) {
645 char *copied_tag;
646 copied_tag = grn_snip_strndupcxx . . $ grn_snip_strndup(5bbb7a0ed225bf59).(ctx, tag, tag_len);
647 if (!copied_tag) {
648 return GRN_NO_MEMORY_AVAILABLEcxx . . $ GRN_NO_MEMORY_AVAILABLE.;
649 }
650 *dest_tag = copied_tag;
651 } else {
652 *dest_tag = tag;
653 }
654 *dest_tag_len = tag_len;
655 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
656 }
657
658 grn_objcxx . . $ grn_obj# *
659 grn_snip_opencxx . . $ grn_snip_open(8867e912bcefadfa).(grn_ctxcxx . . $ grn_ctx# *ctx,
660 int flags,
661 unsigned int width,
662 unsigned int max_results,
663 const char *defaultopentag,
664 unsigned int defaultopentag_len,
665 const char *defaultclosetag,
666 unsigned int defaultclosetag_len,
667 grn_snip_mappingcxx . . $ grn_snip_mapping# *mapping)
668 {
669 int copy_tag;
670 grn_snipcxx . . $ grn_snip# *ret = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
671 if (!(ret = GRN_CALLOCcxx . . $ `lib/grn_alloc.h:42:9`!(sizeof(grn_snip)))) {
672 GRN_LOGcxx . . $ `include/groonga/groonga.h:2493:9`!(ctx, GRN_LOG_ALERT, "grn_snip allocation failed on grn_snip_open");
673 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
674 }
675 if (max_results > MAX_SNIP_RESULT_COUNTcxx . . $ `lib/grn_snip.h:30:9`! || max_results == 0) {
676 GRN_LOGcxx . . $ `include/groonga/groonga.h:2493:9`!(ctx, GRN_LOG_WARNING, "max_results is invalid on grn_snip_open");
677 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(ret);
678 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
679 }
680 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
681 ret->encodingcxx . . $ _grn_snip#encoding. = ctx->encodingcxx . . $ _grn_ctx#encoding.;
682 ret->flagscxx . . $ _grn_snip#flags. = flags;
683 ret->widthcxx . . $ _grn_snip#width. = width;
684 ret->max_resultscxx . . $ _grn_snip#max_results. = max_results;
685 ret->defaultopentagcxx . . $ _grn_snip#defaultopentag. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
686 ret->defaultclosetagcxx . . $ _grn_snip#defaultclosetag. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
687
688 copy_tag = flags & GRN_SNIP_COPY_TAGcxx . . $ `include/groonga/groonga.h:2305:9`!;
689 if (grn_snip_set_default_tagcxx . . $ grn_snip_set_default_tag(b4f7644ba878ea1e).(ctx,
690 &(ret->defaultopentagcxx . . $ _grn_snip#defaultopentag.),
691 &(ret->defaultopentag_lencxx . . $ _grn_snip#defaultopentag_len.),
692 defaultopentag,
693 defaultopentag_len,
694 copy_tag)) {
695 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(ret);
696 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
697 }
698
699 if (grn_snip_set_default_tagcxx . . $ grn_snip_set_default_tag(b4f7644ba878ea1e).(ctx,
700 &(ret->defaultclosetagcxx . . $ _grn_snip#defaultclosetag.),
701 &(ret->defaultclosetag_lencxx . . $ _grn_snip#defaultclosetag_len.),
702 defaultclosetag,
703 defaultclosetag_len,
704 copy_tag)) {
705 if (copy_tag && ret->defaultopentagcxx . . $ _grn_snip#defaultopentag.) {
706 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!((void *)ret->defaultopentag);
707 }
708 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(ret);
709 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
710 }
711
712 ret->cond_capacitycxx . . $ _grn_snip#cond_capacity. = DEFAULT_SNIP_COND_CAPACITYcxx . . $ `lib/grn_snip.h:29:9`!;
713 ret->condcxx . . $ _grn_snip#cond. = (snip_condcxx . . $ snip_cond# *)GRN_MALLOCcxx . . $ `lib/grn_alloc.h:41:9`!(sizeof(snip_cond) * ret->cond_capacity);
714
715 if (!ret->condcxx . . $ _grn_snip#cond.) {
716 if (copy_tag) {
717 if (ret->defaultopentagcxx . . $ _grn_snip#defaultopentag.) {
718 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!((void *)ret->defaultopentag);
719 }
720 if (ret->defaultclosetagcxx . . $ _grn_snip#defaultclosetag.) {
721 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!((void *)ret->defaultclosetag);
722 }
723 }
724 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(ret);
725 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
726 }
727
728 ret->cond_lencxx . . $ _grn_snip#cond_len. = 0;
729 ret->mappingcxx . . $ _grn_snip#mapping. = mapping;
730 ret->nstrcxx . . $ _grn_snip#nstr. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
731 ret->tag_countcxx . . $ _grn_snip#tag_count. = 0;
732 ret->snip_countcxx . . $ _grn_snip#snip_count. = 0;
733 if (ret->flagscxx . . $ _grn_snip#flags. & GRN_SNIP_NORMALIZEcxx . . $ `include/groonga/groonga.h:2304:9`!) {
734 ret->normalizercxx . . $ _grn_snip#normalizer. = GRN_NORMALIZER_AUTOcxx . . $ `include/groonga/string.h:57:9`!;
735 } else {
736 ret->normalizercxx . . $ _grn_snip#normalizer. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
737 }
738 ret->lexiconcxx . . $ _grn_snip#lexicon. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
739 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&(ret->normalizers), 0);
740 ret->delimiter_patterncxx . . $ _grn_snip#delimiter_pattern. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
741 ret->delimiter_pattern_lengthcxx . . $ _grn_snip#delimiter_pattern_length. = 0;
742 #ifdef GRN_SUPPORT_REGEXPcxx . . $ `lib/grn.h:734:11`!
743 ret->delimiter_regexcxx . . $ _grn_snip#delimiter_regex. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
744 #endif
745
746 GRN_DB_OBJ_SET_TYPEcxx . . $ `lib/grn_ctx.h:195:9`!(ret, GRN_SNIPcxx . . $ `include/groonga/groonga.h:881:9`!);
747 {
748 grn_objcxx . . $ grn_obj# *db;
749 grn_idcxx . . $ grn_id# id;
750 db = grn_ctx_dbcxx . . $ grn_ctx_db(ddec8e3b1327ceae).(ctx);
751 id = grn_obj_registercxx . . $ grn_obj_register(5739ee2245199e94).(ctx, db, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0);
752 DB_OBJcxx . . $ `lib/grn_db.h:62:9`!(ret)->headercxx . . $ $anonymous_type_4a7c1014017e4c5d_0#header..domaincxx . . $ _grn_obj_header#domain. = GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!;
753 DB_OBJcxx . . $ `lib/grn_db.h:62:9`!(ret)->rangecxx . . $ $anonymous_type_4a7c1014017e4c5d_0#range. = GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!;
754 grn_db_obj_initcxx . . $ grn_db_obj_init(e57fea19a9dd2af9).(ctx, db, id, DB_OBJcxx . . $ `lib/grn_db.h:62:9`!(ret));
755 }
756
757 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!((grn_obj *)ret);
758 }
759
760 static grn_rccxx . . $ grn_rc#
761 exec_cleancxx . . $ exec_clean(5150f6f5175b280c).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_snipcxx . . $ grn_snip# *snip)
762 {
763 snip_condcxx . . $ snip_cond# *cond, *cond_end;
764 if (snip->nstrcxx . . $ _grn_snip#nstr.) {
765 grn_obj_closecxx . . $ grn_obj_close(4865d068a46d0f83).(ctx, snip->nstrcxx . . $ _grn_snip#nstr.);
766 snip->nstrcxx . . $ _grn_snip#nstr. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
767 }
768 snip->tag_countcxx . . $ _grn_snip#tag_count. = 0;
769 snip->snip_countcxx . . $ _grn_snip#snip_count. = 0;
770 for (cond = snip->condcxx . . $ _grn_snip#cond., cond_end = cond + snip->cond_lencxx . . $ _grn_snip#cond_len.; cond < cond_end;
771 cond++) {
772 grn_snip_cond_reinitcxx . . $ grn_snip_cond_reinit(49091ad9ba26c801).(cond);
773 }
774 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
775 }
776
777 grn_rccxx . . $ grn_rc#
778 grn_snip_closecxx . . $ grn_snip_close(5150f6f5175b280c).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_snipcxx . . $ grn_snip# *snip)
779 {
780 snip_condcxx . . $ snip_cond# *cond, *cond_end;
781 if (!snip) {
782 return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.;
783 }
784 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
785 #ifdef GRN_SUPPORT_REGEXPcxx . . $ `lib/grn.h:734:11`!
786 if (snip->delimiter_regexcxx . . $ _grn_snip#delimiter_regex.) {
787 onig_freecxx . . $ onig_free(b1814a8fd6af504b).(snip->delimiter_regexcxx . . $ _grn_snip#delimiter_regex.);
788 }
789 #endif
790 if (snip->delimiter_patterncxx . . $ _grn_snip#delimiter_pattern.) {
791 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(snip->delimiter_pattern);
792 }
793 if (snip->normalizercxx . . $ _grn_snip#normalizer. && snip->normalizercxx . . $ _grn_snip#normalizer. != GRN_NORMALIZER_AUTOcxx . . $ `include/groonga/string.h:57:9`!) {
794 grn_obj_unrefcxx . . $ grn_obj_unref(cda3a5f3c2e53c6b).(ctx, snip->normalizercxx . . $ _grn_snip#normalizer.);
795 }
796 if (snip->lexiconcxx . . $ _grn_snip#lexicon.) {
797 grn_obj_closecxx . . $ grn_obj_close(4865d068a46d0f83).(ctx, snip->lexiconcxx . . $ _grn_snip#lexicon.);
798 }
799 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &(snip->normalizers));
800 if (snip->flagscxx . . $ _grn_snip#flags. & GRN_SNIP_COPY_TAGcxx . . $ `include/groonga/groonga.h:2305:9`!) {
801 size_t i;
802 snip_condcxx . . $ snip_cond# *sc;
803 const char *dot = snip->defaultopentagcxx . . $ _grn_snip#defaultopentag., *dct = snip->defaultclosetagcxx . . $ _grn_snip#defaultclosetag.;
804 for (i = snip->cond_lencxx . . $ _grn_snip#cond_len., sc = snip->condcxx . . $ _grn_snip#cond.; i; i--, sc++) {
805 if (sc->opentagcxx . . $ _snip_cond#opentag. != dot) {
806 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!((void *)sc->opentag);
807 }
808 if (sc->closetagcxx . . $ _snip_cond#closetag. != dct) {
809 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!((void *)sc->closetag);
810 }
811 }
812 if (dot) {
813 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!((void *)dot);
814 }
815 if (dct) {
816 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!((void *)dct);
817 }
818 }
819 if (snip->nstrcxx . . $ _grn_snip#nstr.) {
820 grn_obj_closecxx . . $ grn_obj_close(4865d068a46d0f83).(ctx, snip->nstrcxx . . $ _grn_snip#nstr.);
821 }
822 for (cond = snip->condcxx . . $ _grn_snip#cond., cond_end = cond + snip->cond_lencxx . . $ _grn_snip#cond_len.; cond < cond_end;
823 cond++) {
824 grn_snip_cond_closecxx . . $ grn_snip_cond_close(14d09e9a60b32ef0).(ctx, cond);
825 }
826 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(snip->cond);
827 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(snip);
828 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(GRN_SUCCESS);
829 }
830
831 grn_rccxx . . $ grn_rc#
832 grn_snip_execcxx . . $ grn_snip_exec(582174da7e0dfc3).(grn_ctxcxx . . $ grn_ctx# *ctx,
833 grn_objcxx . . $ grn_obj# *snip,
834 const char *string,
835 unsigned int string_len,
836 unsigned int *nresults,
837 unsigned int *max_tagged_len)
838 {
839 size_t i;
840 grn_snipcxx . . $ grn_snip# *snip_;
841 int f = GRN_STR_WITH_CHECKScxx . . $ `include/groonga/string.h:42:9`! | GRN_STR_REMOVEBLANKcxx . . $ `include/groonga/string.h:40:9`!;
842 if (!snip || !string || !nresults || !max_tagged_len) {
843 return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.;
844 }
845 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
846 snip_ = (grn_snipcxx . . $ grn_snip# *)snip;
847 exec_cleancxx . . $ exec_clean(5150f6f5175b280c).(ctx, snip_);
848 *nresults = 0;
849 grn_objcxx . . $ grn_obj# *lexicon_or_normalizer = (GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&(snip_->normalizers)) > 0)
850 ? snip_->lexiconcxx . . $ _grn_snip#lexicon.
851 : snip_->normalizercxx . . $ _grn_snip#normalizer.;
852 snip_->nstrcxx . . $ _grn_snip#nstr. =
853 grn_string_opencxx . . $ grn_string_open(e91f62a415156742).(ctx, string, string_len, lexicon_or_normalizer, f);
854 if (!snip_->nstrcxx . . $ _grn_snip#nstr.) {
855 exec_cleancxx . . $ exec_clean(5150f6f5175b280c).(ctx, snip_);
856 GRN_LOGcxx . . $ `include/groonga/groonga.h:2493:9`!(ctx, GRN_LOG_ALERT, "grn_string_open on grn_snip_exec failed !");
857 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
858 }
859 for (i = 0; i < snip_->cond_lencxx . . $ _grn_snip#cond_len.; i++) {
860 grn_bm_tunedbmcxx . . $ grn_bm_tunedbm(a2637678f71cc9af).(ctx, snip_->condcxx . . $ _grn_snip#cond. + i, snip_->nstrcxx . . $ _grn_snip#nstr., snip_->flagscxx . . $ _grn_snip#flags.);
861 }
862
863 {
864 _snip_tag_resultcxx . . $ _snip_tag_result# *tag_result = snip_->tag_resultcxx . . $ _grn_snip#tag_result.;
865 _snip_resultcxx . . $ _snip_result# *snip_result = snip_->snip_resultcxx . . $ _grn_snip#snip_result.;
866 size_t last_end_offset = 0, last_last_end_offset = 0;
867 size_t unfound_cond_count = snip_->cond_lencxx . . $ _grn_snip#cond_len.;
868
869 *max_tagged_len = 0;
870 while (1) {
871 size_t tagged_len = 0, last_tag_end = 0;
872 int_least8_tcxx . . $ int_least8_t# all_stop = 1, found_cond = 0;
873 snip_result->tag_countcxx . . $ $anonymous_type_acd6ebb522869ea0_1#tag_count. = 0;
874
875 while (1) {
876 size_t min_start_offset = (size_t)-1;
877 size_t max_end_offset = 0;
878 snip_condcxx . . $ snip_cond# *cond = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
879
880 /* get condition which have minimum offset and is not stopped */
881 for (i = 0; i < snip_->cond_lencxx . . $ _grn_snip#cond_len.; i++) {
882 if (snip_->condcxx . . $ _grn_snip#cond.[i].stopflagcxx . . $ _snip_cond#stopflag. == SNIPCOND_NONSTOPcxx . . $ `lib/grn_snip.h:36:9`! &&
883 (min_start_offset > snip_->condcxx . . $ _grn_snip#cond.[i].start_offsetcxx . . $ _snip_cond#start_offset. ||
884 (min_start_offset == snip_->condcxx . . $ _grn_snip#cond.[i].start_offsetcxx . . $ _snip_cond#start_offset. &&
885 max_end_offset < snip_->condcxx . . $ _grn_snip#cond.[i].end_offsetcxx . . $ _snip_cond#end_offset.))) {
886 min_start_offset = snip_->condcxx . . $ _grn_snip#cond.[i].start_offsetcxx . . $ _snip_cond#start_offset.;
887 max_end_offset = snip_->condcxx . . $ _grn_snip#cond.[i].end_offsetcxx . . $ _snip_cond#end_offset.;
888 cond = &snip_->condcxx . . $ _grn_snip#cond.[i];
889 }
890 }
891 if (!cond) {
892 break;
893 }
894 /* check whether condition is the first condition in snippet */
895 if (snip_result->tag_countcxx . . $ $anonymous_type_acd6ebb522869ea0_1#tag_count. == 0) {
896 /* skip condition if the number of rest snippet field is smaller than
897 */
898 /* the number of unfound keywords. */
899 if (snip_->max_resultscxx . . $ _grn_snip#max_results. - *nresults <= unfound_cond_count &&
900 cond->countcxx . . $ _snip_cond#count. > 0) {
901 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! exclude_other_cond = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
902 for (i = 0; i < snip_->cond_lencxx . . $ _grn_snip#cond_len.; i++) {
903 if ((snip_->condcxx . . $ _grn_snip#cond. + i) != cond &&
904 snip_->condcxx . . $ _grn_snip#cond.[i].end_offsetcxx . . $ _snip_cond#end_offset. <=
905 cond->start_offsetcxx . . $ _snip_cond#start_offset. + snip_->widthcxx . . $ _grn_snip#width. &&
906 snip_->condcxx . . $ _grn_snip#cond.[i].countcxx . . $ _snip_cond#count. == 0) {
907 exclude_other_cond = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
908 break;
909 }
910 }
911 if (exclude_other_cond) {
912 grn_bm_tunedbmcxx . . $ grn_bm_tunedbm(a2637678f71cc9af).(ctx, cond, snip_->nstrcxx . . $ _grn_snip#nstr., snip_->flagscxx . . $ _grn_snip#flags.);
913 continue;
914 }
915 }
916 snip_result->start_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#start_offset. = cond->start_offsetcxx . . $ _snip_cond#start_offset.;
917 snip_result->first_tag_result_idxcxx . . $ $anonymous_type_acd6ebb522869ea0_1#first_tag_result_idx. = snip_->tag_countcxx . . $ _grn_snip#tag_count.;
918 } else {
919 #ifdef GRN_SUPPORT_REGEXPcxx . . $ `lib/grn.h:734:11`!
920 if (snip_->delimiter_regexcxx . . $ _grn_snip#delimiter_regex.) {
921 size_t range_offset =
922 MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!(snip_result->start_offset + snip_->width, cond->start_offset);
923 OnigPositioncxx . . $ OnigPosition# position =
924 onig_searchcxx . . $ onig_search(68be31d4a4ee5023).(snip_->delimiter_regexcxx . . $ _grn_snip#delimiter_regex.,
925 string,
926 string + string_len,
927 string + snip_result->start_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#start_offset.,
928 string + range_offset,
929 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
930 ONIG_OPTION_NONEcxx . . $ `vendor/onigmo-source/onigmo.h:450:9`!);
931 if (position != ONIG_MISMATCHcxx . . $ `vendor/onigmo-source/onigmo.h:625:9`!) {
932 break;
933 }
934 }
935 #endif
936 if (cond->start_offsetcxx . . $ _snip_cond#start_offset. >= snip_result->start_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#start_offset. + snip_->widthcxx . . $ _grn_snip#width.) {
937 break;
938 }
939 /* check nesting to make valid HTML */
940 /* ToDo: allow <test><te>te</te><st>st</st></test> */
941 if (cond->start_offsetcxx . . $ _snip_cond#start_offset. < last_tag_end) {
942 grn_bm_tunedbmcxx . . $ grn_bm_tunedbm(a2637678f71cc9af).(ctx, cond, snip_->nstrcxx . . $ _grn_snip#nstr., snip_->flagscxx . . $ _grn_snip#flags.);
943 continue;
944 }
945 }
946 if (cond->end_offsetcxx . . $ _snip_cond#end_offset. > snip_result->start_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#start_offset. + snip_->widthcxx . . $ _grn_snip#width.) {
947 /* If a keyword gets across a snippet, */
948 /* it was skipped and never to be tagged. */
949 cond->stopflagcxx . . $ _snip_cond#stopflag. = SNIPCOND_ACROSScxx . . $ `lib/grn_snip.h:38:9`!;
950 grn_bm_tunedbmcxx . . $ grn_bm_tunedbm(a2637678f71cc9af).(ctx, cond, snip_->nstrcxx . . $ _grn_snip#nstr., snip_->flagscxx . . $ _grn_snip#flags.);
951 } else {
952 found_cond = 1;
953 if (cond->countcxx . . $ _snip_cond#count. == 0) {
954 unfound_cond_count--;
955 }
956 cond->countcxx . . $ _snip_cond#count.++;
957 last_end_offset = cond->end_offsetcxx . . $ _snip_cond#end_offset.;
958
959 tag_result->condcxx . . $ $anonymous_type_acd6ebb522869ea0_0#cond. = cond;
960 tag_result->start_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_0#start_offset. = cond->start_offsetcxx . . $ _snip_cond#start_offset.;
961 tag_result->end_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_0#end_offset. = last_tag_end = cond->end_offsetcxx . . $ _snip_cond#end_offset.;
962
963 snip_result->tag_countcxx . . $ $anonymous_type_acd6ebb522869ea0_1#tag_count.++;
964 tag_result++;
965 tagged_len += cond->opentag_lencxx . . $ _snip_cond#opentag_len. + cond->closetag_lencxx . . $ _snip_cond#closetag_len.;
966 if (++snip_->tag_countcxx . . $ _grn_snip#tag_count. >= MAX_SNIP_TAG_COUNTcxx . . $ `lib/grn_snip.h:28:9`!) {
967 break;
968 }
969 grn_bm_tunedbmcxx . . $ grn_bm_tunedbm(a2637678f71cc9af).(ctx, cond, snip_->nstrcxx . . $ _grn_snip#nstr., snip_->flagscxx . . $ _grn_snip#flags.);
970 }
971 }
972 if (!found_cond) {
973 break;
974 }
975 {
976 /*
977 No overlap case:
978 keyword = hij
979 width = 10
980 string = abcdefghijklmnopqrstuvwxyz
981
982 abcdefghijklmnopqrstuvwxyz
983 ^
984 match_start_offset
985 abcdefghijklmnopqrstuvwxyz
986 ^
987 match_end_offset
988 abcdefghijklmnopqrstuvwxyz
989 <->
990 match_width
991 abcdefghijklmnopqrstuvwxyz
992 <--> <->
993 around_width
994 abcdefghijklmnopqrstuvwxyz
995 <-->
996 pre_width
997 abcdefghijklmnopqrstuvwxyz
998 <->
999 post_width
1000 abcdefghijklmnopqrstuvwxyz
1001 <-------->
1002 snip_->width
1003
1004 Overlapped case:
1005 keyword = hij
1006 width = 15
1007 string = abcdefghijklhijklmnopq
1008
1009 abcdefghijklhijklmnopq
1010 ^
1011 match_start_offset
1012 abcdefghijklhijklmnopq
1013 ^
1014 match_end_offset
1015 abcdefghijklhijklmnopq
1016 <------>
1017 match_width
1018 abcdefghijklhijklmnopq
1019 <--> <->
1020 around_width
1021 abcdefghijklhijklmnopq
1022 <-->
1023 pre_width
1024 abcdefghijklhijklmnopq
1025 <->
1026 post_width
1027 abcdefghijklhijklmnopq
1028 <------------->
1029 snip_->width
1030
1031 Delimiter regexp case:
1032 keyword = hij
1033 width = 10
1034 delimiter_regexp = X
1035 string = abcdXfghijkXmnopqrstuvwxyz
1036
1037 abcdXfghijkXmnopqrstuvwxyz
1038 ^
1039 match_start_offset
1040 abcdXfghijkXmnopqrstuvwxyz
1041 ^
1042 match_end_offset
1043 abcdXfghijkXmnopqrstuvwxyz
1044 <->
1045 match_width
1046 abcdXfghijkXmnopqrstuvwxyz
1047 <--> <->
1048 around_width
1049 abcdXfghijkXmnopqrstuvwxyz
1050 <-->
1051 pre_width
1052 abcdXfghijkXmnopqrstuvwxyz
1053 <->
1054 post_width
1055 abcdXfghijkXmnopqrstuvwxyz
1056 <-------->
1057 snip_->width
1058 abcdXfghijkXmnopqrstuvwxyz
1059 ^
1060 snip_result->start_offset (after processed)
1061 abcdXfghijkXmnopqrstuvwxyz
1062 ^
1063 snip_result->end_offset (after processed)
1064 */
1065 size_t match_start_offset = snip_result->start_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#start_offset.;
1066 size_t match_end_offset = last_end_offset;
1067 size_t match_width = match_end_offset - match_start_offset;
1068 size_t pre_width;
1069 size_t post_width;
1070 if (match_width >= snip_->widthcxx . . $ _grn_snip#width.) {
1071 pre_width = post_width = 0;
1072 } else {
1073 size_t around_width = snip_->widthcxx . . $ _grn_snip#width. - match_width;
1074 pre_width = post_width = around_width / 2;
1075 if (around_width % 2 == 1) {
1076 pre_width++;
1077 }
1078 }
1079 {
1080 size_t start_offset_min;
1081 if (match_start_offset < pre_width) {
1082 start_offset_min = 0;
1083 } else {
1084 if (match_end_offset + post_width >= string_len) {
1085 if (string_len < snip_->widthcxx . . $ _grn_snip#width.) {
1086 start_offset_min = 0;
1087 } else {
1088 start_offset_min = string_len - snip_->widthcxx . . $ _grn_snip#width.;
1089 }
1090 } else {
1091 start_offset_min = match_start_offset - pre_width;
1092 }
1093 start_offset_min = grn_snip_find_firstbytecxx . . $ grn_snip_find_firstbyte(3c714cfd8f3d9b8e).(string,
1094 snip_->encodingcxx . . $ _grn_snip#encoding.,
1095 start_offset_min,
1096 1);
1097 }
1098 #ifdef GRN_SUPPORT_REGEXPcxx . . $ `lib/grn.h:734:11`!
1099 if (snip_->delimiter_regexcxx . . $ _grn_snip#delimiter_regex.) {
1100 OnigRegioncxx . . $ OnigRegion# region;
1101 onig_region_initcxx . . $ onig_region_init(46e0b3918c7f0f64).(&region);
1102 OnigPositioncxx . . $ OnigPosition# position = onig_searchcxx . . $ onig_search(68be31d4a4ee5023).(snip_->delimiter_regexcxx . . $ _grn_snip#delimiter_regex.,
1103 string,
1104 string + string_len,
1105 string + match_start_offset,
1106 string + start_offset_min,
1107 &region,
1108 ONIG_OPTION_NONEcxx . . $ `vendor/onigmo-source/onigmo.h:450:9`!);
1109 if (position != ONIG_MISMATCHcxx . . $ `vendor/onigmo-source/onigmo.h:625:9`!) {
1110 start_offset_min = (size_t)(region.endcxx . . $ re_registers#end.[0]);
1111 onig_region_freecxx . . $ onig_region_free(f7147865f954e3eb).(&region, 0);
1112 }
1113 }
1114 #endif
1115 start_offset_min = MAXcxx . . $ `<external>/1231830743887005719/param.h:103:9`!(start_offset_min, last_last_end_offset);
1116 snip_result->start_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#start_offset. = grn_snip_find_firstbytecxx . . $ grn_snip_find_firstbyte(3c714cfd8f3d9b8e).(string,
1117 snip_->encodingcxx . . $ _grn_snip#encoding.,
1118 start_offset_min,
1119 1);
1120 }
1121
1122 {
1123 size_t end_offset_max = snip_result->start_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#start_offset. + snip_->widthcxx . . $ _grn_snip#width.;
1124 if (end_offset_max < match_end_offset) {
1125 end_offset_max = match_end_offset + post_width;
1126 }
1127 #ifdef GRN_SUPPORT_REGEXPcxx . . $ `lib/grn.h:734:11`!
1128 if (snip_->delimiter_regexcxx . . $ _grn_snip#delimiter_regex.) {
1129 size_t valid_end_offset_max;
1130 if (end_offset_max >= string_len) {
1131 valid_end_offset_max = string_len;
1132 } else {
1133 valid_end_offset_max = grn_snip_find_firstbytecxx . . $ grn_snip_find_firstbyte(3c714cfd8f3d9b8e).(string,
1134 snip_->encodingcxx . . $ _grn_snip#encoding.,
1135 end_offset_max,
1136 -1);
1137 }
1138 OnigRegioncxx . . $ OnigRegion# region;
1139 onig_region_initcxx . . $ onig_region_init(46e0b3918c7f0f64).(&region);
1140 OnigPositioncxx . . $ OnigPosition# position = onig_searchcxx . . $ onig_search(68be31d4a4ee5023).(snip_->delimiter_regexcxx . . $ _grn_snip#delimiter_regex.,
1141 string,
1142 string + string_len,
1143 string + match_end_offset,
1144 string + valid_end_offset_max,
1145 &region,
1146 ONIG_OPTION_NONEcxx . . $ `vendor/onigmo-source/onigmo.h:450:9`!);
1147 if (position != ONIG_MISMATCHcxx . . $ `vendor/onigmo-source/onigmo.h:625:9`!) {
1148 end_offset_max = (size_t)(region.begcxx . . $ re_registers#beg.[0]);
1149 onig_region_freecxx . . $ onig_region_free(f7147865f954e3eb).(&region, 0);
1150 }
1151 }
1152 #endif
1153 if (end_offset_max >= string_len) {
1154 snip_result->end_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#end_offset. = string_len;
1155 } else {
1156 snip_result->end_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#end_offset. = grn_snip_find_firstbytecxx . . $ grn_snip_find_firstbyte(3c714cfd8f3d9b8e).(string,
1157 snip_->encodingcxx . . $ _grn_snip#encoding.,
1158 end_offset_max,
1159 -1);
1160 }
1161 }
1162 }
1163 last_last_end_offset = snip_result->end_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#end_offset.;
1164
1165 if (snip_->mappingcxx . . $ _grn_snip#mapping. == GRN_SNIP_MAPPING_HTML_ESCAPEcxx . . $ `include/groonga/groonga.h:2308:9`!) {
1166 tagged_len += count_mapped_charscxx . . $ count_mapped_chars(335c1dc86f5c867f).(&string[snip_result->start_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#start_offset.],
1167 &string[snip_result->end_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#end_offset.]) +
1168 1;
1169 } else {
1170 tagged_len += snip_result->end_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#end_offset. - snip_result->start_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#start_offset. + 1;
1171 }
1172
1173 *max_tagged_len = MAXcxx . . $ `<external>/1231830743887005719/param.h:103:9`!(*max_tagged_len, (unsigned int)tagged_len);
1174
1175 snip_result->last_tag_result_idxcxx . . $ $anonymous_type_acd6ebb522869ea0_1#last_tag_result_idx. = snip_->tag_countcxx . . $ _grn_snip#tag_count. - 1;
1176 (*nresults)++;
1177 snip_result++;
1178
1179 if (*nresults == snip_->max_resultscxx . . $ _grn_snip#max_results. ||
1180 snip_->tag_countcxx . . $ _grn_snip#tag_count. == MAX_SNIP_TAG_COUNTcxx . . $ `lib/grn_snip.h:28:9`!) {
1181 break;
1182 }
1183 for (i = 0; i < snip_->cond_lencxx . . $ _grn_snip#cond_len.; i++) {
1184 if (snip_->condcxx . . $ _grn_snip#cond.[i].stopflagcxx . . $ _snip_cond#stopflag. != SNIPCOND_STOPcxx . . $ `lib/grn_snip.h:37:9`!) {
1185 all_stop = 0;
1186 snip_->condcxx . . $ _grn_snip#cond.[i].stopflagcxx . . $ _snip_cond#stopflag. = SNIPCOND_NONSTOPcxx . . $ `lib/grn_snip.h:36:9`!;
1187 }
1188 }
1189 if (all_stop) {
1190 break;
1191 }
1192 }
1193 }
1194 snip_->snip_countcxx . . $ _grn_snip#snip_count. = *nresults;
1195 snip_->stringcxx . . $ _grn_snip#string. = string;
1196
1197 snip_->max_tagged_lencxx . . $ _grn_snip#max_tagged_len. = *max_tagged_len;
1198
1199 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
1200 }
1201
1202 grn_rccxx . . $ grn_rc#
1203 grn_snip_get_resultcxx . . $ grn_snip_get_result(557ce1c1e283b9f6).(grn_ctxcxx . . $ grn_ctx# *ctx,
1204 grn_objcxx . . $ grn_obj# *snip,
1205 const unsigned int index,
1206 char *result,
1207 unsigned int *result_len)
1208 {
1209 char *p;
1210 size_t i, j, k;
1211 _snip_resultcxx . . $ _snip_result# *sres;
1212 grn_snipcxx . . $ grn_snip# *snip_;
1213
1214 snip_ = (grn_snipcxx . . $ grn_snip# *)snip;
1215 if (snip_->snip_countcxx . . $ _grn_snip#snip_count. <= index || !snip_->nstrcxx . . $ _grn_snip#nstr.) {
1216 return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.;
1217 }
1218
1219 GRN_ASSERTcxx . . $ `lib/grn_ctx.h:70:11`!(snip_->snip_count != 0 && snip_->tag_count != 0);
1220
1221 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
1222 sres = &snip_->snip_resultcxx . . $ _grn_snip#snip_result.[index];
1223 j = sres->first_tag_result_idxcxx . . $ $anonymous_type_acd6ebb522869ea0_1#first_tag_result_idx.;
1224 for (p = result, i = sres->start_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#start_offset.; i < sres->end_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#end_offset.; i++) {
1225 for (; j <= sres->last_tag_result_idxcxx . . $ $anonymous_type_acd6ebb522869ea0_1#last_tag_result_idx. &&
1226 snip_->tag_resultcxx . . $ _grn_snip#tag_result.[j].start_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_0#start_offset. == i;
1227 j++) {
1228 if (snip_->tag_resultcxx . . $ _grn_snip#tag_result.[j].end_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_0#end_offset. > sres->end_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#end_offset.) {
1229 continue;
1230 }
1231 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(p,
1232 snip_->tag_result[j].cond->opentag,
1233 snip_->tag_result[j].cond->opentag_len);
1234 p += snip_->tag_resultcxx . . $ _grn_snip#tag_result.[j].condcxx . . $ $anonymous_type_acd6ebb522869ea0_0#cond.->opentag_lencxx . . $ _snip_cond#opentag_len.;
1235 }
1236
1237 if (snip_->mappingcxx . . $ _grn_snip#mapping. == GRN_SNIP_MAPPING_HTML_ESCAPEcxx . . $ `include/groonga/groonga.h:2308:9`!) {
1238 switch (snip_->stringcxx . . $ _grn_snip#string.[i]) {
1239 case '<':
1240 *p++ = '&';
1241 *p++ = 'l';
1242 *p++ = 't';
1243 *p++ = ';';
1244 break;
1245 case '>':
1246 *p++ = '&';
1247 *p++ = 'g';
1248 *p++ = 't';
1249 *p++ = ';';
1250 break;
1251 case '&':
1252 *p++ = '&';
1253 *p++ = 'a';
1254 *p++ = 'm';
1255 *p++ = 'p';
1256 *p++ = ';';
1257 break;
1258 case '"':
1259 *p++ = '&';
1260 *p++ = 'q';
1261 *p++ = 'u';
1262 *p++ = 'o';
1263 *p++ = 't';
1264 *p++ = ';';
1265 break;
1266 default:
1267 *p++ = snip_->stringcxx . . $ _grn_snip#string.[i];
1268 break;
1269 }
1270 } else {
1271 *p++ = snip_->stringcxx . . $ _grn_snip#string.[i];
1272 }
1273
1274 for (k = sres->last_tag_result_idxcxx . . $ $anonymous_type_acd6ebb522869ea0_1#last_tag_result_idx.;
1275 snip_->tag_resultcxx . . $ _grn_snip#tag_result.[k].end_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_0#end_offset. <= sres->end_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_1#end_offset.;
1276 k--) {
1277 /* TODO: avoid all loop */
1278 if (snip_->tag_resultcxx . . $ _grn_snip#tag_result.[k].end_offsetcxx . . $ $anonymous_type_acd6ebb522869ea0_0#end_offset. == i + 1) {
1279 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(p,
1280 snip_->tag_result[k].cond->closetag,
1281 snip_->tag_result[k].cond->closetag_len);
1282 p += snip_->tag_resultcxx . . $ _grn_snip#tag_result.[k].condcxx . . $ $anonymous_type_acd6ebb522869ea0_0#cond.->closetag_lencxx . . $ _snip_cond#closetag_len.;
1283 }
1284 if (k <= sres->first_tag_result_idxcxx . . $ $anonymous_type_acd6ebb522869ea0_1#first_tag_result_idx.) {
1285 break;
1286 }
1287 };
1288 }
1289 *p = '\0';
1290
1291 if (result_len) {
1292 *result_len = (unsigned int)(p - result);
1293 }
1294 GRN_ASSERTcxx . . $ `lib/grn_ctx.h:70:11`!((unsigned int)(p - result) <= snip_->max_tagged_len);
1295
1296 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
1297 }