PostgreSQL Source Code git master
utilities.c File Reference
#include "snowball_runtime.h"
Include dependency graph for utilities.c:

Go to the source code of this file.

Macros

#define SNOWBALL_RETURN_OK   return 0
 
#define SNOWBALL_RETURN_OR_THROW(R, E)   return R
 
#define SNOWBALL_PROPAGATE_ERR(F)
 
#define CREATE_SIZE   1
 
#define REPLACE_S(Z, B, K, SIZE, S)    SNOWBALL_PROPAGATE_ERR(replace_s(Z, B, K, SIZE, S))
 
#define SLICE_CHECK(Z)   SNOWBALL_PROPAGATE_ERR(slice_check(Z))
 

Functions

symbolcreate_s (void)
 
void lose_s (symbol *p)
 
int skip_utf8 (const symbol *p, int c, int limit, int n)
 
int skip_b_utf8 (const symbol *p, int c, int limit, int n)
 
static int get_utf8 (const symbol *p, int c, int l, int *slot)
 
static int get_b_utf8 (const symbol *p, int c, int lb, int *slot)
 
int in_grouping_U (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int in_grouping_b_U (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int out_grouping_U (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int out_grouping_b_U (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int in_grouping (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int in_grouping_b (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int out_grouping (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int out_grouping_b (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int eq_s (struct SN_env *z, int s_size, const symbol *s)
 
int eq_s_b (struct SN_env *z, int s_size, const symbol *s)
 
int eq_v (struct SN_env *z, const symbol *p)
 
int eq_v_b (struct SN_env *z, const symbol *p)
 
int find_among (struct SN_env *z, const struct among *v, int v_size, int(*call_among_func)(struct SN_env *))
 
int find_among_b (struct SN_env *z, const struct among *v, int v_size, int(*call_among_func)(struct SN_env *))
 
static int increase_size (symbol **p, int n)
 
SNOWBALL_ERR replace_s (struct SN_env *z, int c_bra, int c_ket, int s_size, const symbol *s)
 
static SNOWBALL_ERR slice_check (struct SN_env *z)
 
SNOWBALL_ERR slice_from_s (struct SN_env *z, int s_size, const symbol *s)
 
SNOWBALL_ERR slice_from_v (struct SN_env *z, const symbol *p)
 
SNOWBALL_ERR slice_del (struct SN_env *z)
 
SNOWBALL_ERR insert_s (struct SN_env *z, int bra, int ket, int s_size, const symbol *s)
 
SNOWBALL_ERR insert_v (struct SN_env *z, int bra, int ket, const symbol *p)
 
SNOWBALL_ERR slice_to (struct SN_env *z, symbol **p)
 
SNOWBALL_ERR assign_to (struct SN_env *z, symbol **p)
 
int len_utf8 (const symbol *p)
 

Macro Definition Documentation

◆ CREATE_SIZE

#define CREATE_SIZE   1

Definition at line 18 of file utilities.c.

◆ REPLACE_S

#define REPLACE_S (   Z,
  B,
  K,
  SIZE,
  S 
)     SNOWBALL_PROPAGATE_ERR(replace_s(Z, B, K, SIZE, S))

Definition at line 411 of file utilities.c.

◆ SLICE_CHECK

#define SLICE_CHECK (   Z)    SNOWBALL_PROPAGATE_ERR(slice_check(Z))

Definition at line 430 of file utilities.c.

◆ SNOWBALL_PROPAGATE_ERR

#define SNOWBALL_PROPAGATE_ERR (   F)
Value:
do { \
int snowball_err = F; \
if (snowball_err < 0) return snowball_err; \
} while (0)
#define F(X, Y, Z)
Definition: md5.c:60
while(p+4<=pend)

Definition at line 12 of file utilities.c.

◆ SNOWBALL_RETURN_OK

#define SNOWBALL_RETURN_OK   return 0

Definition at line 10 of file utilities.c.

◆ SNOWBALL_RETURN_OR_THROW

#define SNOWBALL_RETURN_OR_THROW (   R,
 
)    return R

Definition at line 11 of file utilities.c.

Function Documentation

◆ assign_to()

SNOWBALL_ERR assign_to ( struct SN_env z,
symbol **  p 
)

Definition at line 491 of file utilities.c.

491 {
492 int len = z->l;
493 if (CAPACITY(*p) < len) {
495 }
496 memmove(*p, z->p, len * sizeof(symbol));
497 SET_SIZE(*p, len);
499}
unsigned char symbol
Definition: api.h:4
#define CAPACITY(p)
#define SET_SIZE(p, n)
const void size_t len
symbol * p
Definition: api.h:16
int l
Definition: api.h:17
#define SNOWBALL_PROPAGATE_ERR(F)
Definition: utilities.c:12
#define SNOWBALL_RETURN_OK
Definition: utilities.c:10
static int increase_size(symbol **p, int n)
Definition: utilities.c:373

References CAPACITY, increase_size(), SN_env::l, len, SN_env::p, SET_SIZE, SNOWBALL_PROPAGATE_ERR, and SNOWBALL_RETURN_OK.

◆ create_s()

symbol * create_s ( void  )

Definition at line 20 of file utilities.c.

20 {
21 symbol * p;
22 void * mem = malloc(HEAD + (CREATE_SIZE + 1) * sizeof(symbol));
23 if (mem == NULL)
24 SNOWBALL_RETURN_OR_THROW(NULL, std::bad_alloc());
25 p = (symbol *) (HEAD + (char *) mem);
27 SET_SIZE(p, 0);
28 return p;
29}
#define HEAD
#define malloc(a)
#define SNOWBALL_RETURN_OR_THROW(R, E)
Definition: utilities.c:11
#define CREATE_SIZE
Definition: utilities.c:18

References CAPACITY, CREATE_SIZE, HEAD, malloc, SET_SIZE, and SNOWBALL_RETURN_OR_THROW.

Referenced by danish_ISO_8859_1_create_env(), danish_UTF_8_create_env(), dutch_ISO_8859_1_create_env(), dutch_UTF_8_create_env(), finnish_ISO_8859_1_create_env(), finnish_UTF_8_create_env(), and SN_new_env().

◆ eq_s()

int eq_s ( struct SN_env z,
int  s_size,
const symbol s 
)

Definition at line 231 of file utilities.c.

231 {
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}
int c
Definition: api.h:17

References SN_env::c, SN_env::l, and SN_env::p.

Referenced by eq_v(), r_elisions(), r_initial_apostrophe(), r_Lose_infix(), r_Lose_prefix(), r_mark_regions(), r_measure(), r_Prefix_Step2(), r_prelude(), r_remove_pronoun_prefixes(), r_remove_question_prefixes(), r_remove_second_order_prefix(), and russian_UTF_8_stem().

◆ eq_s_b()

◆ eq_v()

int eq_v ( struct SN_env z,
const symbol p 
)

Definition at line 241 of file utilities.c.

241 {
242 return eq_s(z, SIZE(p), p);
243}
#define SIZE(p)
int eq_s(struct SN_env *z, int s_size, const symbol *s)
Definition: utilities.c:231

References eq_s(), and SIZE.

◆ eq_v_b()

int eq_v_b ( struct SN_env z,
const symbol p 
)

Definition at line 245 of file utilities.c.

245 {
246 return eq_s_b(z, SIZE(p), p);
247}
int eq_s_b(struct SN_env *z, int s_size, const symbol *s)
Definition: utilities.c:236

References eq_s_b(), and SIZE.

Referenced by r_tidy(), and r_undouble().

◆ find_among()

int find_among ( struct SN_env z,
const struct among v,
int  v_size,
int(*)(struct SN_env *)  call_among_func 
)

Definition at line 249 of file utilities.c.

250 {
251
252 int i = 0;
253 int j = v_size;
254
255 int c = z->c; int l = z->l;
256 const symbol * q = z->p + c;
257
258 const struct among * w;
259
260 int common_i = 0;
261 int common_j = 0;
262
263 int first_key_inspected = 0;
264
265 while (1) {
266 int k = i + ((j - i) >> 1);
267 int diff = 0;
268 int common = common_i < common_j ? common_i : common_j; /* smaller */
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;
280 common_j = common;
281 } else {
282 i = k;
283 common_i = common;
284 }
285 if (j - i <= 1) {
286 if (i > 0) break; /* v->s has been inspected */
287 if (j == i) break; /* only one item in v */
288
289 /* - but now we need to go round once more to get
290 v->s inspected. This looks messy, but is actually
291 the optimal approach. */
292
293 if (first_key_inspected) break;
294 first_key_inspected = 1;
295 }
296 }
297 w = v + i;
298 while (1) {
299 if (common_i >= w->s_size) {
300 z->c = c + w->s_size;
301 if (!w->function) return w->result;
302 z->af = w->function;
303 if (call_among_func(z)) {
304 z->c = c + w->s_size;
305 return w->result;
306 }
307 }
308 if (!w->substring_i) return 0;
309 w += w->substring_i;
310 }
311}
int j
Definition: isn.c:78
int i
Definition: isn.c:77
char * c
int af
Definition: api.h:18
int substring_i
const symbol * s
int function

References SN_env::af, SN_env::c, among::function, i, j, SN_env::l, SN_env::p, among::result, among::s, among::s_size, and among::substring_i.

Referenced by r_canonical_form(), r_Checks1(), r_cleaning(), r_cyr_to_lat(), r_exception1(), r_fix_va_start(), r_initial_apostrophe(), r_initial_morph(), r_Lose_infix(), r_Lose_prefix(), r_mark_regions(), r_norm(), r_Normalize_post(), r_Normalize_pre(), r_postlude(), r_Prefix_Step1(), r_Prefix_Step2(), r_Prefix_Step3_Verb(), r_Prefix_Step3a_Noun(), r_Prefix_Step3b_Noun(), r_Prefix_Step4_Verb(), r_prelude(), r_remove_first_order_prefix(), r_remove_pronoun_prefixes(), r_remove_question_prefixes(), r_remove_second_order_prefix(), and r_verb_exceptions().

◆ find_among_b()

int find_among_b ( struct SN_env z,
const struct among v,
int  v_size,
int(*)(struct SN_env *)  call_among_func 
)

Definition at line 315 of file utilities.c.

316 {
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
326 int common_i = 0;
327 int common_j = 0;
328
329 int first_key_inspected = 0;
330
331 while (1) {
332 int k = i + ((j - i) >> 1);
333 int diff = 0;
334 int common = common_i < common_j ? common_i : common_j;
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 }
344 if (diff < 0) { j = k; common_j = common; }
345 else { i = k; common_i = common; }
346 if (j - i <= 1) {
347 if (i > 0) break;
348 if (j == i) break;
349 if (first_key_inspected) break;
350 first_key_inspected = 1;
351 }
352 }
353 w = v + i;
354 while (1) {
355 if (common_i >= w->s_size) {
356 z->c = c - w->s_size;
357 if (!w->function) return w->result;
358 z->af = w->function;
359 if (call_among_func(z)) {
360 z->c = c - w->s_size;
361 return w->result;
362 }
363 }
364 if (!w->substring_i) return 0;
365 w += w->substring_i;
366 }
367}

References SN_env::af, SN_env::c, among::function, i, j, SN_env::lb, SN_env::p, among::result, among::s, among::s_size, and among::substring_i.

Referenced by hindi_UTF_8_stem(), r_aditzak(), r_adjectival(), r_adjective(), r_adjetiboak(), r_attached_pronoun(), r_case(), r_case_ending(), r_case_other(), r_case_special(), r_combo_suffix(), r_consonant_pair(), r_correlative(), r_degrees(), r_deriv(), r_derivational(), r_double(), r_emphasis(), r_ending(), r_et_condition(), r_factive(), r_final_apostrophe(), r_fix_chdz(), r_fix_conflicts(), r_fix_ending(), r_i_verb_suffix(), r_instrum(), r_izenak(), r_lengthen_V(), r_LONG(), r_LONGV(), r_main_suffix(), r_mark_cAsInA(), r_mark_DA(), r_mark_DAn(), r_mark_DUr(), r_mark_lAr(), r_mark_lArI(), r_mark_nA(), r_mark_ncA(), r_mark_ndA(), r_mark_ndAn(), r_mark_nU(), r_mark_nUn(), r_mark_nUz(), r_mark_possessives(), r_mark_sUn(), r_mark_sUnUz(), r_mark_yDU(), r_mark_ylA(), r_mark_ymUs_(), r_mark_ysA(), r_mark_yUm(), r_mark_yUz(), r_merged_numeral(), r_normalize_consonant(), r_Normalize_post(), r_noun(), r_noun_sfx(), r_nu(), r_other_endings(), r_other_suffix(), r_owned(), r_particle_etc(), r_perfective_gerund(), r_plur_owner(), r_plural(), r_plural_three_first_cases(), r_possessive(), r_post_process_last_consonants(), r_pronoun(), r_reflexive(), r_remove_category_1(), r_remove_category_2(), r_remove_category_3(), r_remove_command_suffixes(), r_remove_common_word_endings(), r_remove_endings(), r_remove_particle(), r_remove_plural_suffix(), r_remove_possessive_pronoun(), r_remove_question_suffixes(), r_remove_suffix(), r_remove_tense_suffix(), r_remove_vetrumai_urupukal(), r_residual_form(), r_residual_suffix(), r_sing_owner(), r_special_noun_endings(), r_standard_suffix(), r_step1(), r_step2(), r_step_0(), r_Step_1(), r_step_1(), r_Step_1a(), r_Step_1b(), r_Step_1c(), r_Step_2(), r_step_2a(), r_step_2b(), r_step_2c(), r_step_2d(), r_Step_3(), r_step_3(), r_Step_4(), r_step_4(), r_Step_5(), r_step_5a(), r_step_5b(), r_step_5c(), r_step_5d(), r_step_5e(), r_step_5f(), r_step_5g(), r_step_5h(), r_step_5i(), r_step_5j(), r_step_5k(), r_step_5l(), r_step_5m(), r_Step_6(), r_step_6(), r_Step_7(), r_step_7(), r_step_s1(), r_step_s10(), r_step_s2(), r_step_s3(), r_step_s4(), r_step_s5(), r_step_s6(), r_step_s7(), r_step_s8(), r_step_s9(), r_Suffix_Noun_Step1a(), r_Suffix_Noun_Step2a(), r_Suffix_Verb_Step1(), r_Suffix_Verb_Step2a(), r_Suffix_Verb_Step2b(), r_Suffix_Verb_Step2c(), r_t_plural(), r_tidy_up(), r_tolower(), r_ujn_suffix(), r_un_double(), r_undouble(), r_undouble_kpt(), r_uninflected(), r_v_ending(), r_verb(), r_verb_sfx(), r_verb_suffix(), r_vowel_suffix(), and r_y_verb_suffix().

◆ get_b_utf8()

static int get_b_utf8 ( const symbol p,
int  c,
int  lb,
int *  slot 
)
static

Definition at line 109 of file utilities.c.

109 {
110 int a, b;
111 if (c <= lb) return 0;
112 b = p[--c];
113 if (b < 0x80 || c == lb) { /* 1000 0000 */
114 *slot = b;
115 return 1;
116 }
117 a = b & 0x3F;
118 b = p[--c];
119 if (b >= 0xC0 || c == lb) { /* 1100 0000 */
120 *slot = (b & 0x1F) << 6 | a;
121 return 2;
122 }
123 a |= (b & 0x3F) << 6;
124 b = p[--c];
125 if (b >= 0xE0 || c == lb) { /* 1110 0000 */
126 *slot = (b & 0xF) << 12 | a;
127 return 3;
128 }
129 *slot = (p[--c] & 0x7) << 18 | (b & 0x3F) << 12 | a;
130 return 4;
131}
int b
Definition: isn.c:74
int a
Definition: isn.c:73

References a, and b.

Referenced by in_grouping_b_U(), and out_grouping_b_U().

◆ get_utf8()

static int get_utf8 ( const symbol p,
int  c,
int  l,
int *  slot 
)
static

Definition at line 87 of file utilities.c.

87 {
88 int b0, b1, b2;
89 if (c >= l) return 0;
90 b0 = p[c++];
91 if (b0 < 0xC0 || c == l) { /* 1100 0000 */
92 *slot = b0;
93 return 1;
94 }
95 b1 = p[c++] & 0x3F;
96 if (b0 < 0xE0 || c == l) { /* 1110 0000 */
97 *slot = (b0 & 0x1F) << 6 | b1;
98 return 2;
99 }
100 b2 = p[c++] & 0x3F;
101 if (b0 < 0xF0 || c == l) { /* 1111 0000 */
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}

Referenced by in_grouping_U(), and out_grouping_U().

◆ in_grouping()

int in_grouping ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 183 of file utilities.c.

183 {
184 do {
185 int ch;
186 if (z->c >= z->l) return -1;
187 ch = z->p[z->c];
188 if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
189 return 1;
190 z->c++;
191 } while (repeat);
192 return 0;
193}
Datum repeat(PG_FUNCTION_ARGS)

References SN_env::c, SN_env::l, SN_env::p, and repeat().

Referenced by porter_ISO_8859_1_stem(), r_elisions(), r_Lose_infix(), r_Lose_prefix(), r_mark_regions(), r_measure(), r_prelude(), and r_remove_first_order_prefix().

◆ in_grouping_b()

int in_grouping_b ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 195 of file utilities.c.

195 {
196 do {
197 int ch;
198 if (z->c <= z->lb) return -1;
199 ch = z->p[z->c - 1];
200 if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
201 return 1;
202 z->c--;
203 } while (repeat);
204 return 0;
205}

References SN_env::c, SN_env::lb, SN_env::p, and repeat().

Referenced by r_case_ending(), r_et_condition(), r_lengthen_V(), r_main_suffix(), r_other_suffix(), r_particle_etc(), r_shortv(), r_standard_suffix(), r_Step_1b(), r_Step_2(), r_t_plural(), r_tidy(), r_undouble(), r_V(), r_VI(), r_vowel_suffix(), and r_VX().

◆ in_grouping_b_U()

int in_grouping_b_U ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 145 of file utilities.c.

145 {
146 do {
147 int ch;
148 int w = get_b_utf8(z->p, z->c, z->lb, & 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;
153 } while (repeat);
154 return 0;
155}
static int get_b_utf8(const symbol *p, int c, int lb, int *slot)
Definition: utilities.c:109

References SN_env::c, get_b_utf8(), SN_env::lb, SN_env::p, and repeat().

Referenced by r_case_ending(), r_CONSONANT(), r_correlative(), r_degrees(), r_emphasis(), r_et_condition(), r_i_plural(), r_lengthen_V(), r_main_suffix(), r_mark_sU(), r_mark_suffix_with_optional_n_consonant(), r_mark_suffix_with_optional_s_consonant(), r_mark_suffix_with_optional_U_vowel(), r_mark_suffix_with_optional_y_consonant(), r_mark_yU(), r_other_suffix(), r_particle_etc(), r_plural_three_first_cases(), r_shortv(), r_standard_suffix(), r_Step_1b(), r_Step_2(), r_step_3(), r_step_4(), r_step_5b(), r_step_5c(), r_t_plural(), r_tidy(), r_undouble(), r_undouble_kpt(), r_V(), r_verb(), r_VI(), r_vowel_suffix(), and r_VX().

◆ in_grouping_U()

int in_grouping_U ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 133 of file utilities.c.

133 {
134 do {
135 int ch;
136 int w = get_utf8(z->p, z->c, z->l, & 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;
141 } while (repeat);
142 return 0;
143}
static int get_utf8(const symbol *p, int c, int l, int *slot)
Definition: utilities.c:87

References SN_env::c, get_utf8(), SN_env::l, SN_env::p, and repeat().

Referenced by lithuanian_UTF_8_stem(), porter_UTF_8_stem(), r_elisions(), r_Lose_infix(), r_Lose_prefix(), r_mark_regions(), r_measure(), r_prelude(), and r_remove_first_order_prefix().

◆ increase_size()

static int increase_size ( symbol **  p,
int  n 
)
static

Definition at line 373 of file utilities.c.

373 {
374 int new_size = n + 20;
375 void * mem = realloc((char *) *p - HEAD,
376 HEAD + (new_size + 1) * sizeof(symbol));
377 symbol * q;
378 if (mem == NULL) return -1;
379 q = (symbol *) (HEAD + (char *)mem);
380 CAPACITY(q) = new_size;
381 *p = q;
382 return 0;
383}
#define realloc(a, b)

References CAPACITY, HEAD, and realloc.

Referenced by assign_to(), replace_s(), and slice_to().

◆ insert_s()

SNOWBALL_ERR insert_s ( struct SN_env z,
int  bra,
int  ket,
int  s_size,
const symbol s 
)

Definition at line 464 of file utilities.c.

464 {
465 REPLACE_S(z, bra, ket, s_size, s);
466 if (bra <= z->ket) {
467 int adjustment = s_size - (ket - bra);
468 z->ket += adjustment;
469 if (bra <= z->bra) z->bra += adjustment;
470 }
472}
int ket
Definition: api.h:17
int bra
Definition: api.h:17
#define REPLACE_S(Z, B, K, SIZE, S)
Definition: utilities.c:411

References SN_env::bra, SN_env::ket, REPLACE_S, among::s, among::s_size, and SNOWBALL_RETURN_OK.

Referenced by insert_v(), r_Step_1b(), r_Step_2(), r_step_2a(), and r_Step_3().

◆ insert_v()

SNOWBALL_ERR insert_v ( struct SN_env z,
int  bra,
int  ket,
const symbol p 
)

Definition at line 474 of file utilities.c.

474 {
475 return insert_s(z, bra, ket, SIZE(p), p);
476}
SNOWBALL_ERR insert_s(struct SN_env *z, int bra, int ket, int s_size, const symbol *s)
Definition: utilities.c:464

References insert_s(), and SIZE.

Referenced by r_lengthen_V().

◆ len_utf8()

◆ lose_s()

void lose_s ( symbol p)

Definition at line 31 of file utilities.c.

31 {
32 if (p == NULL) return;
33 free((char *) p - HEAD);
34}
#define free(a)

References free, and HEAD.

Referenced by danish_ISO_8859_1_close_env(), danish_UTF_8_close_env(), dutch_ISO_8859_1_close_env(), dutch_UTF_8_close_env(), finnish_ISO_8859_1_close_env(), finnish_UTF_8_close_env(), and SN_delete_env().

◆ out_grouping()

int out_grouping ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 207 of file utilities.c.

207 {
208 do {
209 int ch;
210 if (z->c >= z->l) return -1;
211 ch = z->p[z->c];
212 if (!(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0))
213 return 1;
214 z->c++;
215 } while (repeat);
216 return 0;
217}

References SN_env::c, SN_env::l, SN_env::p, and repeat().

Referenced by indonesian_ISO_8859_1_stem(), porter_ISO_8859_1_stem(), r_mark_regions(), r_measure(), r_prelude(), and r_remove_second_order_prefix().

◆ out_grouping_b()

int out_grouping_b ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 219 of file utilities.c.

219 {
220 do {
221 int ch;
222 if (z->c <= z->lb) return -1;
223 ch = z->p[z->c - 1];
224 if (!(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0))
225 return 1;
226 z->c--;
227 } while (repeat);
228 return 0;
229}

References SN_env::c, SN_env::lb, SN_env::p, and repeat().

Referenced by r_C(), r_e_ending(), r_en_ending(), r_et_condition(), r_i_verb_suffix(), r_lengthen_V(), r_main_suffix(), r_residual_suffix(), r_shortv(), r_standard_suffix(), r_Step_1a(), r_Step_1b(), r_Step_1c(), and r_un_accent().

◆ out_grouping_b_U()

int out_grouping_b_U ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 169 of file utilities.c.

169 {
170 do {
171 int ch;
172 int w = get_b_utf8(z->p, z->c, z->lb, & 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;
177 } while (repeat);
178 return 0;
179}

References SN_env::c, get_b_utf8(), SN_env::lb, SN_env::p, and repeat().

Referenced by r_append_U_to_stems_ending_with_d_or_g(), r_C(), r_check_vowel_harmony(), r_e_ending(), r_en_ending(), r_et_condition(), r_i_verb_suffix(), r_lengthen_V(), r_long_word(), r_main_suffix(), r_mark_suffix_with_optional_U_vowel(), r_residual_suffix(), r_shortv(), r_standard_suffix(), r_Step_1a(), r_Step_1b(), r_Step_1c(), r_un_accent(), and r_verb_suffix().

◆ out_grouping_U()

int out_grouping_U ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 157 of file utilities.c.

157 {
158 do {
159 int ch;
160 int w = get_utf8(z->p, z->c, z->l, & 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;
165 } while (repeat);
166 return 0;
167}

References SN_env::c, get_utf8(), SN_env::l, SN_env::p, and repeat().

Referenced by indonesian_UTF_8_stem(), lithuanian_UTF_8_stem(), porter_UTF_8_stem(), r_mark_regions(), r_measure(), r_more_than_one_syllable_word(), r_prelude(), and r_remove_second_order_prefix().

◆ replace_s()

SNOWBALL_ERR replace_s ( struct SN_env z,
int  c_bra,
int  c_ket,
int  s_size,
const symbol s 
)

Definition at line 389 of file utilities.c.

390{
391 int adjustment = s_size - (c_ket - c_bra);
392 if (adjustment != 0) {
393 int len = SIZE(z->p);
394 if (adjustment + len > CAPACITY(z->p)) {
395 SNOWBALL_PROPAGATE_ERR(increase_size(&z->p, adjustment + len));
396 }
397 memmove(z->p + c_ket + adjustment,
398 z->p + c_ket,
399 (len - c_ket) * sizeof(symbol));
400 SET_SIZE(z->p, adjustment + len);
401 z->l += adjustment;
402 if (z->c >= c_ket)
403 z->c += adjustment;
404 else if (z->c > c_bra)
405 z->c = c_bra;
406 }
407 if (s_size) memmove(z->p + c_bra, s, s_size * sizeof(symbol));
409}

References SN_env::c, CAPACITY, increase_size(), SN_env::l, len, SN_env::p, among::s, among::s_size, SET_SIZE, SIZE, SNOWBALL_PROPAGATE_ERR, and SNOWBALL_RETURN_OK.

Referenced by SN_set_current().

◆ skip_b_utf8()

int skip_b_utf8 ( const symbol p,
int  c,
int  limit,
int  n 
)

Definition at line 68 of file utilities.c.

68 {
69 int b;
70 if (n < 0) return -1;
71 for (; n > 0; n--) {
72 if (c <= limit) return -1;
73 b = p[--c];
74 if (b >= 0x80) { /* 1000 0000 */
75 while (c > limit) {
76 b = p[c];
77 if (b >= 0xC0) break; /* 1100 0000 */
78 c--;
79 }
80 }
81 }
82 return c;
83}

References b.

Referenced by arabic_UTF_8_stem(), r_case_ending(), r_consonant_pair(), r_emphasis(), r_lengthen_V(), r_long_word(), r_mark_suffix_with_optional_n_consonant(), r_mark_suffix_with_optional_s_consonant(), r_mark_suffix_with_optional_U_vowel(), r_mark_suffix_with_optional_y_consonant(), r_plural_three_first_cases(), r_standard_suffix(), r_Step_1a(), r_Step_1b(), r_tidy(), r_tolower(), r_un_double(), r_undouble(), r_verb_suffix(), and r_VX().

◆ skip_utf8()

int skip_utf8 ( const symbol p,
int  c,
int  limit,
int  n 
)

Definition at line 43 of file utilities.c.

43 {
44 int b;
45 if (n < 0) return -1;
46 for (; n > 0; n--) {
47 if (c >= limit) return -1;
48 b = p[c++];
49 if (b >= 0xC0) { /* 1100 0000 */
50 while (c < limit) {
51 b = p[c];
52 if (b >= 0xC0 || b < 0x80) break;
53 /* break unless b is 10------ */
54 c++;
55 }
56 }
57 }
58 return c;
59}

References b.

Referenced by english_UTF_8_stem(), hindi_UTF_8_stem(), polish_UTF_8_stem(), porter_UTF_8_stem(), r_canonical_form(), r_cleaning(), r_cyr_to_lat(), r_Lose_infix(), r_Lose_prefix(), r_mark_regions(), r_norm(), r_Normalize_post(), r_Normalize_pre(), r_postlude(), r_prelude(), r_remove_proper_noun_suffix(), and russian_UTF_8_stem().

◆ slice_check()

static SNOWBALL_ERR slice_check ( struct SN_env z)
static

Definition at line 414 of file utilities.c.

414 {
415
416 if (z->bra < 0 ||
417 z->bra > z->ket ||
418 z->ket > z->l ||
419 z->l > SIZE(z->p)) /* this line could be removed */
420 {
421#if 0
422 fprintf(stderr, "faulty slice operation:\n");
423 debug(z, -1, 0);
424#endif
425 SNOWBALL_RETURN_OR_THROW(-1, std::logic_error("Snowball slice invalid"));
426 }
428}
#define fprintf(file, fmt, msg)
Definition: cubescan.l:21
static bool debug
Definition: initdb.c:161

References SN_env::bra, debug, fprintf, SN_env::ket, SN_env::l, SN_env::p, SIZE, SNOWBALL_RETURN_OK, and SNOWBALL_RETURN_OR_THROW.

◆ slice_del()

SNOWBALL_ERR slice_del ( struct SN_env z)

Definition at line 443 of file utilities.c.

443 {
444 SLICE_CHECK(z);
445 {
446 int slice_size = z->ket - z->bra;
447 if (slice_size != 0) {
448 int len = SIZE(z->p);
449 memmove(z->p + z->bra,
450 z->p + z->ket,
451 (len - z->ket) * sizeof(symbol));
452 SET_SIZE(z->p, len - slice_size);
453 z->l -= slice_size;
454 if (z->c >= z->ket)
455 z->c -= slice_size;
456 else if (z->c > z->bra)
457 z->c = z->bra;
458 }
459 }
460 z->ket = z->bra;
462}
#define SLICE_CHECK(Z)
Definition: utilities.c:430

References SN_env::bra, SN_env::c, SN_env::ket, SN_env::l, len, SN_env::p, SET_SIZE, SIZE, SLICE_CHECK, and SNOWBALL_RETURN_OK.

Referenced by hindi_UTF_8_stem(), portuguese_ISO_8859_1_stem(), portuguese_UTF_8_stem(), r_aditzak(), r_adjectival(), r_adjective(), r_adjetiboak(), r_attached_pronoun(), r_case(), r_case_ending(), r_case_other(), r_consonant_pair(), r_correlative(), r_degrees(), r_deriv(), r_derivational(), r_e_ending(), r_elisions(), r_emphasis(), r_en_ending(), r_ending(), r_factive(), r_fix_ending(), r_i_plural(), r_i_verb_suffix(), r_initial_morph(), r_instrum(), r_izenak(), r_Lose_infix(), r_Lose_prefix(), r_main_suffix(), r_Normalize_pre(), r_noun(), r_noun_sfx(), r_nu(), r_other_endings(), r_other_suffix(), r_owned(), r_particle_etc(), r_perfective_gerund(), r_plur_owner(), r_plural(), r_plural_three_first_cases(), r_possessive(), r_postlude(), r_Prefix_Step2(), r_Prefix_Step3a_Noun(), r_Prefix_Step3b_Noun(), r_prelude(), r_pronoun(), r_reflexive(), r_remove_category_1(), r_remove_category_2(), r_remove_category_3(), r_remove_command_suffixes(), r_remove_common_word_endings(), r_remove_endings(), r_remove_first_order_prefix(), r_remove_particle(), r_remove_plural_suffix(), r_remove_possessive_pronoun(), r_remove_pronoun_prefixes(), r_remove_proper_noun_suffix(), r_remove_question_prefixes(), r_remove_second_order_prefix(), r_remove_suffix(), r_remove_tense_suffix(), r_remove_vetrumai_urupukal(), r_residual_form(), r_residual_suffix(), r_sing_owner(), r_standard_suffix(), r_stem_nominal_verb_suffixes(), r_stem_noun_suffixes(), r_stem_suffix_chain_before_ki(), r_step1(), r_step2(), r_step_0(), r_Step_1(), r_Step_1a(), r_Step_1b(), r_Step_1c(), r_Step_2(), r_step_2a(), r_step_2b(), r_step_2c(), r_step_2d(), r_Step_3(), r_step_3(), r_Step_4(), r_step_4(), r_Step_5(), r_Step_5a(), r_step_5a(), r_Step_5b(), r_step_5b(), r_step_5c(), r_step_5d(), r_step_5e(), r_step_5f(), r_step_5g(), r_step_5h(), r_step_5i(), r_step_5j(), r_step_5k(), r_step_5l(), r_step_5m(), r_step_6(), r_step_7(), r_step_s1(), r_step_s10(), r_step_s2(), r_step_s3(), r_step_s4(), r_step_s5(), r_step_s6(), r_step_s7(), r_step_s8(), r_step_s9(), r_Suffix_Noun_Step1a(), r_Suffix_Noun_Step1b(), r_Suffix_Noun_Step2a(), r_Suffix_Noun_Step2b(), r_Suffix_Noun_Step2c1(), r_Suffix_Noun_Step2c2(), r_Suffix_Noun_Step3(), r_Suffix_Verb_Step1(), r_Suffix_Verb_Step2a(), r_Suffix_Verb_Step2b(), r_Suffix_Verb_Step2c(), r_t_plural(), r_tidy(), r_tidy_up(), r_ujn_suffix(), r_un_double(), r_undouble(), r_verb(), r_verb_sfx(), r_verb_suffix(), r_vowel_suffix(), r_y_verb_suffix(), russian_KOI8_R_stem(), and russian_UTF_8_stem().

◆ slice_from_s()

SNOWBALL_ERR slice_from_s ( struct SN_env z,
int  s_size,
const symbol s 
)

Definition at line 432 of file utilities.c.

432 {
433 SLICE_CHECK(z);
434 REPLACE_S(z, z->bra, z->ket, s_size, s);
435 z->ket = z->bra + s_size;
437}

References SN_env::bra, SN_env::ket, REPLACE_S, among::s, among::s_size, SLICE_CHECK, and SNOWBALL_RETURN_OK.

Referenced by french_ISO_8859_1_stem(), french_UTF_8_stem(), porter_ISO_8859_1_stem(), porter_UTF_8_stem(), r_adjetiboak(), r_append_U_to_stems_ending_with_d_or_g(), r_attached_pronoun(), r_canonical_form(), r_case_other(), r_case_special(), r_cleaning(), r_combo_suffix(), r_cyr_to_lat(), r_deriv(), r_exception1(), r_final_apostrophe(), r_fix_chdz(), r_fix_conflicts(), r_fix_ending(), r_fix_gd(), r_fix_va_start(), r_initial_apostrophe(), r_initial_morph(), r_izenak(), r_lengthen_V(), r_Lose_infix(), r_Lose_prefix(), r_main_suffix(), r_mark_regions(), r_norm(), r_normalize_consonant(), r_Normalize_post(), r_Normalize_pre(), r_other_suffix(), r_owned(), r_plur_owner(), r_plural(), r_plural_three_first_cases(), r_possessive(), r_post_process_last_consonants(), r_postlude(), r_Prefix_Step1(), r_Prefix_Step3_Verb(), r_Prefix_Step3b_Noun(), r_Prefix_Step4_Verb(), r_prelude(), r_remove_common_word_endings(), r_remove_endings(), r_remove_first_order_prefix(), r_remove_plural_suffix(), r_remove_question_suffixes(), r_remove_tense_suffix(), r_remove_um(), r_remove_vetrumai_urupukal(), r_residual_form(), r_residual_suffix(), r_sing_owner(), r_special_noun_endings(), r_standard_suffix(), r_step_0(), r_Step_1(), r_step_1(), r_Step_1a(), r_Step_1b(), r_Step_1c(), r_Step_2(), r_step_2b(), r_step_2c(), r_step_2d(), r_Step_3(), r_step_3(), r_Step_4(), r_step_4(), r_step_5a(), r_step_5b(), r_step_5c(), r_step_5d(), r_step_5e(), r_step_5f(), r_step_5g(), r_step_5h(), r_step_5i(), r_step_5j(), r_step_5k(), r_step_5l(), r_step_5m(), r_Step_6(), r_step_6(), r_Step_7(), r_step_s1(), r_step_s10(), r_step_s2(), r_step_s3(), r_step_s4(), r_step_s5(), r_step_s6(), r_step_s7(), r_step_s8(), r_step_s9(), r_Suffix_All_alef_maqsura(), r_tolower(), r_un_accent(), r_undouble_kpt(), r_v_ending(), r_verb(), r_verb_exceptions(), russian_KOI8_R_stem(), russian_UTF_8_stem(), and slice_from_v().

◆ slice_from_v()

SNOWBALL_ERR slice_from_v ( struct SN_env z,
const symbol p 
)

Definition at line 439 of file utilities.c.

439 {
440 return slice_from_s(z, SIZE(p), p);
441}
SNOWBALL_ERR slice_from_s(struct SN_env *z, int s_size, const symbol *s)
Definition: utilities.c:432

References SIZE, and slice_from_s().

◆ slice_to()

SNOWBALL_ERR slice_to ( struct SN_env z,
symbol **  p 
)

Definition at line 478 of file utilities.c.

478 {
479 SLICE_CHECK(z);
480 {
481 int len = z->ket - z->bra;
482 if (CAPACITY(*p) < len) {
484 }
485 memmove(*p, z->p + z->bra, len * sizeof(symbol));
486 SET_SIZE(*p, len);
487 }
489}

References SN_env::bra, CAPACITY, increase_size(), SN_env::ket, len, SN_env::p, SET_SIZE, SLICE_CHECK, SNOWBALL_PROPAGATE_ERR, and SNOWBALL_RETURN_OK.

Referenced by r_lengthen_V(), r_tidy(), and r_undouble().