Debian Codegraph @

lib/proc/proc_normalize.c

raw symbols SCIP
1 /*
2 Copyright (C) 2009-2018 Brazil
3 Copyright (C) 2021-2026 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_proc.h"cxx . . $ `<file>/lib/grn_proc.h`/
21 #include "../grn_ctx.h"cxx . . $ `<file>/lib/grn_ctx.h`/
22
23 #include <groonga/plugin.h>cxx . . $ `<file>/include/groonga/plugin.h`/
24
25 static int
26 parse_normalize_flagscxx . . $ parse_normalize_flags(d324cdd0f6cb1846).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_raw_stringcxx . . $ grn_raw_string# *flags_raw)
27 {
28 int flags = 0;
29 const char *names, *names_end;
30
31 names = flags_raw->valuecxx . . $ $anonymous_type_7f733dd816802915_0#value.;
32 names_end = names + flags_raw->lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length.;
33 while (names < names_end) {
34 if (*names == '|' || *names == ' ') {
35 names += 1;
36 continue;
37 }
38
39 #define CHECK_FLAGcxx . . $ `lib/proc/proc_normalize.c:39:9`!(name)\
40 if (((size_t)(names_end - names) >= (sizeof(#name) - 1)) && \
41 (!memcmp(names, #name, sizeof(#name) - 1))) {\
42 flags |= GRN_STRING_ ## name;\
43 names += sizeof(#name) - 1;\
44 continue;\
45 }
46
47 CHECK_FLAGcxx . . $ `lib/proc/proc_normalize.c:39:9`!(REMOVE_BLANK);
48 CHECK_FLAGcxx . . $ `lib/proc/proc_normalize.c:39:9`!(WITH_TYPES);
49 CHECK_FLAGcxx . . $ `lib/proc/proc_normalize.c:39:9`!(WITH_CHECKS);
50 CHECK_FLAGcxx . . $ `lib/proc/proc_normalize.c:39:9`!(REMOVE_TOKENIZED_DELIMITER);
51
52 #define GRN_STRING_NONEcxx . . $ `lib/proc/proc_normalize.c:52:9`! 0
53 CHECK_FLAGcxx . . $ `lib/proc/proc_normalize.c:39:9`!(NONE);
54 #undef GRN_STRING_NONEcxx . . $ `lib/proc/proc_normalize.c:52:9`!
55
56 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[normalize] invalid flag: <%.*s>",
57 (int)(names_end - names), names);
58 return 0;
59 #undef CHECK_FLAGcxx . . $ `lib/proc/proc_normalize.c:39:9`!
60 }
61
62 return flags;
63 }
64
65 static grn_objcxx . . $ grn_obj# *
66 command_normalizecxx . . $ command_normalize(fd082858389c8bb0).(grn_ctxcxx . . $ grn_ctx# *ctx, int nargs, grn_objcxx . . $ grn_obj# **args, grn_user_datacxx . . $ grn_user_data# *user_data)
67 {
68 const char *context_tag = "[normalize]";
69 grn_raw_stringcxx . . $ grn_raw_string# normalizer_raw;
70 grn_raw_stringcxx . . $ grn_raw_string# string_raw;
71 grn_raw_stringcxx . . $ grn_raw_string# flags_raw;
72 grn_raw_stringcxx . . $ grn_raw_string# normalizers_raw;
73
74 #define GET_VALUEcxx . . $ `lib/proc/proc_normalize.c:74:9`!(name) \
75 name ## _raw.value = \
76 grn_plugin_proc_get_var_string(ctx, \
77 user_data, \
78 #name, \
79 strlen(#name), \
80 &(name ## _raw.length))
81
82 GET_VALUEcxx . . $ `lib/proc/proc_normalize.c:74:9`!(normalizer);
83 GET_VALUEcxx . . $ `lib/proc/proc_normalize.c:74:9`!(string);
84 GET_VALUEcxx . . $ `lib/proc/proc_normalize.c:74:9`!(flags);
85 GET_VALUEcxx . . $ `lib/proc/proc_normalize.c:74:9`!(normalizers);
86
87 #undef GET_VALUEcxx . . $ `lib/proc/proc_normalize.c:74:9`!
88
89 if (normalizers_raw.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. == 0 && normalizer_raw.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. > 0) {
90 normalizers_raw = normalizer_raw;
91 }
92 if (normalizers_raw.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. == 0) {
93 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
94 GRN_INVALID_ARGUMENT,
95 "%s normalizer name is missing",
96 context_tag);
97 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
98 }
99
100 {
101 int flags;
102 int n_elements = 3;
103 grn_objcxx . . $ grn_obj# *lexicon;
104 grn_objcxx . . $ grn_obj# *grn_string;
105 unsigned int normalized_length_in_bytes;
106 unsigned int normalized_n_characters;
107 const uint64_tcxx . . $ uint64_t# *offsets;
108
109 flags = parse_normalize_flagscxx . . $ parse_normalize_flags(d324cdd0f6cb1846).(ctx, &flags_raw);
110 if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
111 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
112 }
113
114 lexicon = grn_proc_lexicon_opencxx . . $ grn_proc_lexicon_open(44e18c98336dc3bd).(ctx,
115 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
116 &normalizers_raw,
117 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
118 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
119 context_tag);
120 if (!lexicon) {
121 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
122 }
123
124 grn_string = grn_string_opencxx . . $ grn_string_open(e91f62a415156742).(ctx,
125 string_raw.valuecxx . . $ $anonymous_type_7f733dd816802915_0#value.,
126 (unsigned int)(string_raw.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length.),
127 lexicon,
128 flags);
129
130 offsets = grn_string_get_offsetscxx . . $ grn_string_get_offsets(29c3efd045e091f0).(ctx, grn_string);
131 if (offsets) {
132 n_elements++;
133 }
134
135 grn_ctx_output_map_opencxx . . $ grn_ctx_output_map_open(f0f392d632556531).(ctx, "RESULT", n_elements);
136 {
137 const char *normalized;
138
139 grn_string_get_normalizedcxx . . $ grn_string_get_normalized(fcb0da4d05783f05).(ctx,
140 grn_string,
141 &normalized,
142 &normalized_length_in_bytes,
143 &normalized_n_characters);
144 grn_ctx_output_cstrcxx . . $ grn_ctx_output_cstr(777524e3d10dd7b4).(ctx, "normalized");
145 grn_ctx_output_strcxx . . $ grn_ctx_output_str(bd29ebb5071afc4b).(ctx, normalized, normalized_length_in_bytes);
146 }
147 {
148 const unsigned char *types;
149
150 types = grn_string_get_typescxx . . $ grn_string_get_types(e641985a04b6a30).(ctx, grn_string);
151 grn_ctx_output_cstrcxx . . $ grn_ctx_output_cstr(777524e3d10dd7b4).(ctx, "types");
152 if (types) {
153 unsigned int i;
154 grn_ctx_output_array_opencxx . . $ grn_ctx_output_array_open(f0f392d632556531).(ctx, "types", (int)normalized_n_characters);
155 for (i = 0; i <= normalized_n_characters; i++) {
156 grn_ctx_output_cstrcxx . . $ grn_ctx_output_cstr(777524e3d10dd7b4).(ctx, grn_char_type_to_stringcxx . . $ grn_char_type_to_string(4f7a31af04a5b084).(types[i]));
157 }
158 grn_ctx_output_array_closecxx . . $ grn_ctx_output_array_close(b578cd6e53d5fe91).(ctx);
159 } else {
160 grn_ctx_output_array_opencxx . . $ grn_ctx_output_array_open(f0f392d632556531).(ctx, "types", 0);
161 grn_ctx_output_array_closecxx . . $ grn_ctx_output_array_close(b578cd6e53d5fe91).(ctx);
162 }
163 }
164 {
165 const short *checks;
166
167 checks = grn_string_get_checkscxx . . $ grn_string_get_checks(392ec27081c21988).(ctx, grn_string);
168 grn_ctx_output_cstrcxx . . $ grn_ctx_output_cstr(777524e3d10dd7b4).(ctx, "checks");
169 if (checks) {
170 unsigned int i;
171 grn_ctx_output_array_opencxx . . $ grn_ctx_output_array_open(f0f392d632556531).(ctx, "checks", (int)normalized_length_in_bytes);
172 for (i = 0; i < normalized_length_in_bytes; i++) {
173 grn_ctx_output_int32cxx . . $ grn_ctx_output_int32(55555b1fc84b4259).(ctx, checks[i]);
174 }
175 grn_ctx_output_array_closecxx . . $ grn_ctx_output_array_close(b578cd6e53d5fe91).(ctx);
176 } else {
177 grn_ctx_output_array_opencxx . . $ grn_ctx_output_array_open(f0f392d632556531).(ctx, "checks", 0);
178 grn_ctx_output_array_closecxx . . $ grn_ctx_output_array_close(b578cd6e53d5fe91).(ctx);
179 }
180 }
181 if (offsets) {
182 unsigned int i;
183
184 grn_ctx_output_cstrcxx . . $ grn_ctx_output_cstr(777524e3d10dd7b4).(ctx, "offsets");
185 grn_ctx_output_array_opencxx . . $ grn_ctx_output_array_open(f0f392d632556531).(ctx, "offsets", (int)normalized_n_characters);
186 for (i = 0; i <= normalized_n_characters; i++) {
187 grn_ctx_output_uint64cxx . . $ grn_ctx_output_uint64(150f498c5f9d24bd).(ctx, offsets[i]);
188 }
189 grn_ctx_output_array_closecxx . . $ grn_ctx_output_array_close(b578cd6e53d5fe91).(ctx);
190 }
191
192 grn_ctx_output_map_closecxx . . $ grn_ctx_output_map_close(b578cd6e53d5fe91).(ctx);
193
194 grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, grn_string);
195
196 grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, lexicon);
197 }
198
199 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
200 }
201
202 void
203 grn_proc_init_normalizecxx . . $ grn_proc_init_normalize(b578cd6e53d5fe91).(grn_ctxcxx . . $ grn_ctx# *ctx)
204 {
205 grn_expr_varcxx . . $ grn_expr_var# vars[4];
206
207 grn_plugin_expr_var_initcxx . . $ grn_plugin_expr_var_init(680ef4125f11597f).(ctx, &(vars[0]), "normalizer", -1);
208 grn_plugin_expr_var_initcxx . . $ grn_plugin_expr_var_init(680ef4125f11597f).(ctx, &(vars[1]), "string", -1);
209 grn_plugin_expr_var_initcxx . . $ grn_plugin_expr_var_init(680ef4125f11597f).(ctx, &(vars[2]), "flags", -1);
210 grn_plugin_expr_var_initcxx . . $ grn_plugin_expr_var_init(680ef4125f11597f).(ctx, &(vars[3]), "normalizers", -1);
211 grn_plugin_command_createcxx . . $ grn_plugin_command_create(2dfd920bb40f3149).(ctx,
212 "normalize", -1,
213 command_normalizecxx . . $ command_normalize(fd082858389c8bb0).,
214 4,
215 vars);
216 }