PostgreSQL Source Code: src/backend/snowball/libstemmer/utilities.c Source File (original) (raw)
1#include "snowball_runtime.h"
2
3#ifdef SNOWBALL_RUNTIME_THROW_EXCEPTIONS
4# include
5# include
6# define SNOWBALL_RETURN_OK return
7# define SNOWBALL_RETURN_OR_THROW(R, E) throw E
8# define SNOWBALL_PROPAGATE_ERR(F) F
9#else
10# define SNOWBALL_RETURN_OK return 0
11# define SNOWBALL_RETURN_OR_THROW(R, E) return R
12# define SNOWBALL_PROPAGATE_ERR(F) do { \
13 int snowball_err = F; \
14 if (snowball_err < 0) return snowball_err; \
15 } while (0)
16#endif
17
18#define CREATE_SIZE 1
19
30
32 if (p == NULL) return;
34}
35
36
37
38
39
40
41
42
44 int b;
45 if (n < 0) return -1;
46 for (; n > 0; n--) {
47 if (c >= limit) return -1;
49 if (b >= 0xC0) {
50 while (c < limit) {
52 if (b >= 0xC0 || b < 0x80) break;
53
54 c++;
55 }
56 }
57 }
58 return c;
59}
60
61
62
63
64
65
66
67
69 int b;
70 if (n < 0) return -1;
71 for (; n > 0; n--) {
72 if (c <= limit) return -1;
74 if (b >= 0x80) {
75 while (c > limit) {
77 if (b >= 0xC0) break;
78 c--;
79 }
80 }
81 }
82 return c;
83}
84
85
86
89 if (c >= l) return 0;
92 *slot = b0;
93 return 1;
94 }
97 *slot = (b0 & 0x1F) << 6 | b1;
98 return 2;
99 }
101 if (b0 < 0xF0 || c == l) {
102 *slot = (b0 & 0xF) << 12 | b1 << 6 | b2;
103 return 3;
104 }
105 *slot = (b0 & 0x7) << 18 | b1 << 12 | b2 << 6 | (p[c] & 0x3F);
106 return 4;
107}
108
111 if (c <= lb) return 0;
113 if (b < 0x80 || c == lb) {
114 *slot = b;
115 return 1;
116 }
119 if (b >= 0xC0 || c == lb) {
120 *slot = (b & 0x1F) << 6 | a;
121 return 2;
122 }
125 if (b >= 0xE0 || c == lb) {
126 *slot = (b & 0xF) << 12 | a;
127 return 3;
128 }
129 *slot = (p[--c] & 0x7) << 18 | (b & 0x3F) << 12 | a;
130 return 4;
131}
132
134 do {
135 int ch;
137 if (!w) return -1;
138 if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
139 return w;
140 z->c += w;
142 return 0;
143}
144
146 do {
147 int ch;
149 if (!w) return -1;
150 if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
151 return w;
152 z->c -= w;
154 return 0;
155}
156
158 do {
159 int ch;
161 if (!w) return -1;
162 if (!(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0))
163 return w;
164 z->c += w;
166 return 0;
167}
168
170 do {
171 int ch;
173 if (!w) return -1;
174 if (!(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0))
175 return w;
176 z->c -= w;
178 return 0;
179}
180
181
182
184 do {
185 int ch;
186 if (z->c >= z->l) return -1;
188 if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
189 return 1;
190 z->c++;
192 return 0;
193}
194
196 do {
197 int ch;
198 if (z->c <= z->lb) return -1;
200 if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
201 return 1;
202 z->c--;
204 return 0;
205}
206
208 do {
209 int ch;
210 if (z->c >= z->l) return -1;
212 if (!(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0))
213 return 1;
214 z->c++;
216 return 0;
217}
218
220 do {
221 int ch;
222 if (z->c <= z->lb) return -1;
224 if (!(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0))
225 return 1;
226 z->c--;
228 return 0;
229}
230
232 if (z->l - z->c < s_size || memcmp(z->p + z->c, s, s_size * sizeof(symbol)) != 0) return 0;
233 z->c += s_size; return 1;
234}
235
237 if (z->c - z->lb < s_size || memcmp(z->p + z->c - s_size, s, s_size * sizeof(symbol)) != 0) return 0;
238 z->c -= s_size; return 1;
239}
240
244
248
251
252 int i = 0;
253 int j = v_size;
254
255 int c = z->c; int l = z->l;
257
258 const struct among * w;
259
262
264
265 while (1) {
266 int k = i + ((j - i) >> 1);
267 int diff = 0;
269 w = v + k;
270 {
271 int i2; for (i2 = common; i2 < w->s_size; i2++) {
272 if (c + common == l) { diff = -1; break; }
273 diff = q[common] - w->s[i2];
274 if (diff != 0) break;
275 common++;
276 }
277 }
278 if (diff < 0) {
279 j = k;
281 } else {
282 i = k;
284 }
286 if (i > 0) break;
288
289
290
291
292
295 }
296 }
297 w = v + i;
298 while (1) {
306 }
307 }
310 }
311}
312
313
314
317
318 int i = 0;
319 int j = v_size;
320
321 int c = z->c; int lb = z->lb;
322 const symbol * q = z->p + c - 1;
323
324 const struct among * w;
325
328
330
331 while (1) {
332 int k = i + ((j - i) >> 1);
333 int diff = 0;
335 w = v + k;
336 {
337 int i2; for (i2 = w->s_size - 1 - common; i2 >= 0; i2--) {
338 if (c - common == lb) { diff = -1; break; }
339 diff = q[- common] - w->s[i2];
340 if (diff != 0) break;
341 common++;
342 }
343 }
345 else { i = k; common_i = common; }
347 if (i > 0) break;
351 }
352 }
353 w = v + i;
354 while (1) {
362 }
363 }
366 }
367}
368
369
370
371
372
378 if (mem == NULL) return -1;
381 *p = q;
382 return 0;
383}
384
385
386
387
388
390{
396 }
406 }
409}
410
411# define REPLACE_S(Z, B, K, SIZE, S) \
412 SNOWBALL_PROPAGATE_ERR(replace_s(Z, B, K, SIZE, S))
413
415
416 if (z->bra < 0 ||
420 {
421#if 0
424#endif
426 }
428}
429
430# define SLICE_CHECK(Z) SNOWBALL_PROPAGATE_ERR(slice_check(Z))
431
438
442
445 {
458 }
459 }
462}
463
473
477
490
495 }
499}
500
502 int size = SIZE(p);
503 int len = 0;
504 while (size--) {
506 if (b >= 0xC0 || b < 0x80) ++len;
507 }
508 return len;
509}
#define fprintf(file, fmt, msg)
static void repeat(struct vars *v, struct state *lp, struct state *rp, int m, int n)
#define REPLACE_S(Z, B, K, SIZE, S)
#define SNOWBALL_RETURN_OR_THROW(R, E)
int out_grouping_U(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
int in_grouping_U(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
SNOWBALL_ERR insert_s(struct SN_env *z, int bra, int ket, int s_size, const symbol *s)
int eq_v_b(struct SN_env *z, const symbol *p)
SNOWBALL_ERR slice_from_s(struct SN_env *z, int s_size, const symbol *s)
int in_grouping(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
SNOWBALL_ERR slice_to(struct SN_env *z, symbol **p)
SNOWBALL_ERR assign_to(struct SN_env *z, symbol **p)
SNOWBALL_ERR slice_from_v(struct SN_env *z, const symbol *p)
int eq_s(struct SN_env *z, int s_size, const symbol *s)
SNOWBALL_ERR insert_v(struct SN_env *z, int bra, int ket, const symbol *p)
#define SNOWBALL_PROPAGATE_ERR(F)
static SNOWBALL_ERR slice_check(struct SN_env *z)
int eq_v(struct SN_env *z, const symbol *p)
SNOWBALL_ERR replace_s(struct SN_env *z, int c_bra, int c_ket, int s_size, const symbol *s)
static int get_utf8(const symbol *p, int c, int l, int *slot)
int out_grouping_b(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
int find_among_b(struct SN_env *z, const struct among *v, int v_size, int(*call_among_func)(struct SN_env *))
#define SNOWBALL_RETURN_OK
int in_grouping_b_U(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
int skip_b_utf8(const symbol *p, int c, int limit, int n)
int eq_s_b(struct SN_env *z, int s_size, const symbol *s)
int out_grouping(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
SNOWBALL_ERR slice_del(struct SN_env *z)
int out_grouping_b_U(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
int skip_utf8(const symbol *p, int c, int limit, int n)
int in_grouping_b(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
int len_utf8(const symbol *p)
static int get_b_utf8(const symbol *p, int c, int lb, int *slot)
static int increase_size(symbol **p, int n)
int find_among(struct SN_env *z, const struct among *v, int v_size, int(*call_among_func)(struct SN_env *))