8 if (mem == NULL)
return NULL;
16 if (p == NULL)
return;
31 if (
c >= limit)
return -1;
36 if (
b >= 0xC0 ||
b < 0x80)
break;
56 if (
c <= limit)
return -1;
75 if (b0 < 0xC0 ||
c == l) {
80 if (b0 < 0xE0 ||
c == l) {
81 *slot = (b0 & 0x1F) << 6 | b1;
85 if (b0 < 0xF0 ||
c == l) {
86 *slot = (b0 & 0xF) << 12 | b1 << 6 | b2;
89 *slot = (b0 & 0x7) << 18 | b1 << 12 | b2 << 6 | (p[
c] & 0x3F);
95 if (
c <= lb)
return 0;
97 if (
b < 0x80 ||
c == lb) {
103 if (
b >= 0xC0 ||
c == lb) {
104 *slot = (
b & 0x1F) << 6 |
a;
107 a |= (
b & 0x3F) << 6;
109 if (
b >= 0xE0 ||
c == lb) {
110 *slot = (
b & 0xF) << 12 |
a;
113 *slot = (p[--
c] & 0x7) << 18 | (
b & 0x3F) << 12 |
a;
122 if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
134 if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
146 if (!(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0))
158 if (!(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0))
170 if (z->
c >= z->
l)
return -1;
172 if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
182 if (z->
c <= z->
lb)
return -1;
184 if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
194 if (z->
c >= z->
l)
return -1;
196 if (!(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0))
206 if (z->
c <= z->
lb)
return -1;
208 if (!(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0))
216 if (z->
l - z->
c < s_size || memcmp(z->
p + z->
c, s, s_size *
sizeof(
symbol)) != 0)
return 0;
217 z->
c += s_size;
return 1;
221 if (z->
c - z->
lb < s_size || memcmp(z->
p + z->
c - s_size, s, s_size *
sizeof(
symbol)) != 0)
return 0;
222 z->
c -= s_size;
return 1;
238 int c = z->
c;
int l = z->
l;
241 const struct among * w;
246 int first_key_inspected = 0;
249 int k =
i + ((
j -
i) >> 1);
251 int common = common_i < common_j ? common_i : common_j;
254 int i2;
for (i2 = common; i2 < w->
s_size; i2++) {
255 if (
c + common == l) { diff = -1;
break; }
256 diff = q[common] - w->
s[i2];
257 if (diff != 0)
break;
276 if (first_key_inspected)
break;
277 first_key_inspected = 1;
282 if (common_i >= w->
s_size) {
303 int c = z->
c;
int lb = z->
lb;
306 const struct among * w;
311 int first_key_inspected = 0;
314 int k =
i + ((
j -
i) >> 1);
316 int common = common_i < common_j ? common_i : common_j;
319 int i2;
for (i2 = w->
s_size - 1 - common; i2 >= 0; i2--) {
320 if (
c - common == lb) { diff = -1;
break; }
321 diff = q[- common] - w->
s[i2];
322 if (diff != 0)
break;
326 if (diff < 0) {
j = k; common_j = common; }
327 else {
i = k; common_i = common; }
331 if (first_key_inspected)
break;
332 first_key_inspected = 1;
337 if (common_i >= w->
s_size) {
357 int new_size = n + 20;
380 if (z->
p == NULL)
return -1;
382 adjustment =
s_size - (c_ket - c_bra);
384 if (adjustment != 0) {
387 if (z->
p == NULL)
return -1;
389 memmove(z->
p + c_ket + adjustment,
396 else if (z->
c > c_bra)
401 *adjptr = adjustment;
414 fprintf(stderr,
"faulty slice operation:\n");
439 if (bra <= z->bra) z->
bra += adjustment;
440 if (bra <= z->ket) z->
ket += adjustment;
483 if (
b >= 0xC0 ||
b < 0x80) ++
len;
489 extern void debug(
struct SN_env * z,
int number,
int line_count) {
491 int limit =
SIZE(z->
p);
493 if (number >= 0)
printf(
"%3d (line %4d): [%d]'", number, line_count,limit);
494 for (
i = 0;
i <= limit;
i++) {
502 if (ch == 0) ch =
'#';
static void PGresult * res
Datum repeat(PG_FUNCTION_ARGS)
static pg_noinline void Size size
int(* function)(struct SN_env *)
int insert_v(struct SN_env *z, int bra, int ket, const symbol *p)
int find_among_b(struct SN_env *z, const struct among *v, int v_size)
int out_grouping_U(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
int insert_s(struct SN_env *z, int bra, int ket, int s_size, const symbol *s)
static int slice_check(struct SN_env *z)
int slice_del(struct SN_env *z)
int in_grouping_U(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
static symbol * increase_size(symbol *p, int n)
int eq_v_b(struct SN_env *z, const symbol *p)
symbol * assign_to(struct SN_env *z, symbol *p)
int in_grouping(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 replace_s(struct SN_env *z, int c_bra, int c_ket, int s_size, const symbol *s, int *adjptr)
symbol * slice_to(struct SN_env *z, symbol *p)
int eq_v(struct SN_env *z, const symbol *p)
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 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)
int out_grouping_b_U(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
int slice_from_v(struct SN_env *z, const symbol *p)
int find_among(struct SN_env *z, const struct among *v, int v_size)
int skip_utf8(const symbol *p, int c, int limit, int n)
int slice_from_s(struct SN_env *z, int s_size, const symbol *s)
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)