24 #ifndef _ISOC99_SOURCE
25 #define _ISOC99_SOURCE
30 grn_str_charlen_utf8(
grn_ctx *ctx,
const unsigned char *str,
const unsigned char *end)
34 if (end <= str || !*str) {
42 if ((
unsigned int)(len - 2) >= 3) {
44 "grn_str_charlen_utf8(): first byte is invalid");
47 if (str + len > end) {
49 "grn_str_charlen_utf8(): incomplete character");
52 for (i = 1; i < len; ++
i) {
53 if ((str[i] & 0xc0) != 0x80) {
55 "grn_str_charlen_utf8(): <%d>th byte is invalid",
70 unsigned char *p = (
unsigned char *) str;
71 if (!*p) {
return 0; }
89 for (b = 0x40, w = 0; b && (*p &
b); b >>= 1, w++);
94 for (size = 1; w--; size++) {
95 if (!*++p || (*p & 0xc0) != 0x80) {
108 if (0xa0 <= *p && *p <= 0xdf) {
111 }
else if (!(*(p + 1))) {
134 unsigned char *p = (
unsigned char *) str;
135 if (p >= (
unsigned char *)end) {
return 0; }
139 if ((p + 1) < (
unsigned char *)end) {
150 return grn_str_charlen_utf8(ctx, p, (
unsigned char *)end);
155 if (0xa0 <= *p && *p <= 0xdf) {
158 }
else if (++p >= (
unsigned char *)end) {
182 static unsigned char symbol[] = {
183 ',',
'.', 0,
':',
';',
'?',
'!', 0, 0, 0,
'`', 0,
'^',
'~',
'_', 0, 0, 0,
184 0, 0, 0, 0, 0, 0, 0,
'-',
'-',
'/',
'\\', 0, 0,
'|', 0, 0, 0,
'\'', 0,
185 '"',
'(',
')', 0, 0,
'[',
']',
'{',
'}', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
186 '+',
'-', 0, 0, 0,
'=', 0,
'<',
'>', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
187 '$', 0, 0,
'%',
'#',
'&',
'*',
'@', 0, 0, 0, 0, 0, 0, 0, 0
193 static uint16_t hankana[] = {
194 0xa1a1, 0xa1a3, 0xa1d6, 0xa1d7, 0xa1a2, 0xa1a6, 0xa5f2, 0xa5a1, 0xa5a3,
195 0xa5a5, 0xa5a7, 0xa5a9, 0xa5e3, 0xa5e5, 0xa5e7, 0xa5c3, 0xa1bc, 0xa5a2,
196 0xa5a4, 0xa5a6, 0xa5a8, 0xa5aa, 0xa5ab, 0xa5ad, 0xa5af, 0xa5b1, 0xa5b3,
197 0xa5b5, 0xa5b7, 0xa5b9, 0xa5bb, 0xa5bd, 0xa5bf, 0xa5c1, 0xa5c4, 0xa5c6,
198 0xa5c8, 0xa5ca, 0xa5cb, 0xa5cc, 0xa5cd, 0xa5ce, 0xa5cf, 0xa5d2, 0xa5d5,
199 0xa5d8, 0xa5db, 0xa5de, 0xa5df, 0xa5e0, 0xa5e1, 0xa5e2, 0xa5e4, 0xa5e6,
200 0xa5e8, 0xa5e9, 0xa5ea, 0xa5eb, 0xa5ec, 0xa5ed, 0xa5ef, 0xa5f3, 0xa1ab,
203 static unsigned char dakuten[] = {
204 0xf4, 0, 0, 0, 0, 0xac, 0, 0xae, 0, 0xb0, 0, 0xb2, 0, 0xb4, 0, 0xb6, 0,
205 0xb8, 0, 0xba, 0, 0xbc, 0, 0xbe, 0, 0xc0, 0, 0xc2, 0, 0, 0xc5, 0, 0xc7,
206 0, 0xc9, 0, 0, 0, 0, 0, 0, 0xd0, 0, 0, 0xd3, 0, 0, 0xd6, 0, 0, 0xd9, 0,
209 static unsigned char handaku[] = {
210 0xd1, 0, 0, 0xd4, 0, 0, 0xd7, 0, 0, 0xda, 0, 0, 0xdd
213 const unsigned char *s, *s_, *e;
214 unsigned char *d, *d0, *d_,
b;
216 size_t size = nstr->
orig_blen, length = 0;
221 d0 = (
unsigned char *) nstr->
norm;
239 cp = ctypes = nstr->
ctypes;
240 e = (
unsigned char *)nstr->
orig + size;
241 for (s = s_ = (
unsigned char *) nstr->
orig, d = d_ = d0; s < e; s++) {
243 if (((s + 1) < e) && (*(s + 1) & 0x80)) {
244 unsigned char c1 = *s++, c2 = *s, c3 = 0;
247 if (c1 == 0x8e && 0xa0 <= c2 && c2 <= 0xdf) {
248 uint16_t c = hankana[c2 - 0xa0];
251 if (d > d0 + 1 && d[-2] == 0xa5
252 && 0xa6 <= d[-1] && d[-1] <= 0xdb && (b = dakuten[d[-1] - 0xa6])) {
254 if (ch) { ch[-1] += 2; s_ += 2; }
257 *d++ = c >> 8; *d = c & 0xff;
261 if (d > d0 + 1 && d[-2] == 0xa5
262 && 0xcf <= d[-1] && d[-1] <= 0xdb && (b = handaku[d[-1] - 0xcf])) {
264 if (ch) { ch[-1] += 2; s_ += 2; }
267 *d++ = c >> 8; *d = c & 0xff;
271 *d++ = c >> 8; *d = c & 0xff;
306 if (c2 >= 0xa4 && (c3 = symbol[c2 - 0xa4])) {
322 if (
'a' <= c3 && c3 <=
'z') {
325 }
else if (
'A' <= c3 && c3 <=
'Z') {
328 }
else if (
'0' <= c3 && c3 <=
'9') {
366 unsigned char c = *s;
392 *d = (
'A' <= c) ? c + 0x20 : c;
396 *d = (c <=
'Z') ? c + 0x20 : c;
415 if (cp) { *cp++ = ctype; }
417 *ch++ = (int16_t)(s + 1 - s_);
419 while (++d_ < d) { *ch++ = 0; }
430 const char *grn_nfkc_map1(
const unsigned char *str);
431 const char *grn_nfkc_map2(
const unsigned char *prefix,
const unsigned char *suffix);
437 const unsigned char *s, *s_, *s__ = NULL, *p, *p2, *pe, *e;
438 unsigned char *d, *d_, *de;
440 size_t length = 0, ls, lp, size = nstr->
orig_blen, ds = size * 3;
460 d = (
unsigned char *)nstr->
norm;
463 e = (
unsigned char *)nstr->
orig + size;
464 for (s = s_ = (
unsigned char *)nstr->
orig; ; s += ls) {
465 if (!(ls = grn_str_charlen_utf8(ctx, s, e))) {
468 if ((p = (
unsigned char *)grn_nfkc_map1(s))) {
469 pe = p + strlen((
char *)p);
474 if (d_ && (p2 = (
unsigned char *)grn_nfkc_map2(d_, p))) {
476 pe = p + strlen((
char *)p);
486 if (!(lp = grn_str_charlen_utf8(ctx, p, pe))) {
489 if ((*p ==
' ' && removeblankp) || *p < 0x20 ) {
494 ds += (ds >> 1) + lp;
502 d = norm + (d - (
unsigned char *)nstr->
norm);
503 nstr->
norm = (
char *)norm;
512 ch = checks + (ch - nstr->
checks);
523 cp = ctypes + (cp - nstr->
ctypes);
537 *ch++ = (int16_t)(s + ls - s_);
541 for (i = lp; i > 1; i--) { *ch++ = 0; }
557 static uint16_t hankana[] = {
558 0x8140, 0x8142, 0x8175, 0x8176, 0x8141, 0x8145, 0x8392, 0x8340, 0x8342,
559 0x8344, 0x8346, 0x8348, 0x8383, 0x8385, 0x8387, 0x8362, 0x815b, 0x8341,
560 0x8343, 0x8345, 0x8347, 0x8349, 0x834a, 0x834c, 0x834e, 0x8350, 0x8352,
561 0x8354, 0x8356, 0x8358, 0x835a, 0x835c, 0x835e, 0x8360, 0x8363, 0x8365,
562 0x8367, 0x8369, 0x836a, 0x836b, 0x836c, 0x836d, 0x836e, 0x8371, 0x8374,
563 0x8377, 0x837a, 0x837d, 0x837e, 0x8380, 0x8381, 0x8382, 0x8384, 0x8386,
564 0x8388, 0x8389, 0x838a, 0x838b, 0x838c, 0x838d, 0x838f, 0x8393, 0x814a,
567 static unsigned char dakuten[] = {
568 0x94, 0, 0, 0, 0, 0x4b, 0, 0x4d, 0, 0x4f, 0, 0x51, 0, 0x53, 0, 0x55, 0,
569 0x57, 0, 0x59, 0, 0x5b, 0, 0x5d, 0, 0x5f, 0, 0x61, 0, 0, 0x64, 0, 0x66,
570 0, 0x68, 0, 0, 0, 0, 0, 0, 0x6f, 0, 0, 0x72, 0, 0, 0x75, 0, 0, 0x78, 0,
573 static unsigned char handaku[] = {
574 0x70, 0, 0, 0x73, 0, 0, 0x76, 0, 0, 0x79, 0, 0, 0x7c
577 const unsigned char *s, *s_;
578 unsigned char *d, *d0, *d_,
b, *e;
580 size_t size = nstr->
orig_blen, length = 0;
585 d0 = (
unsigned char *) nstr->
norm;
603 cp = ctypes = nstr->
ctypes;
604 e = (
unsigned char *)nstr->
orig + size;
605 for (s = s_ = (
unsigned char *) nstr->
orig, d = d_ = d0; s < e; s++) {
607 if (0xa0 <= *s && *s <= 0xdf) {
608 uint16_t c = hankana[*s - 0xa0];
611 if (d > d0 + 1 && d[-2] == 0x83
612 && 0x45 <= d[-1] && d[-1] <= 0x7a && (b = dakuten[d[-1] - 0x45])) {
614 if (ch) { ch[-1]++; s_++; }
617 *d++ = c >> 8; *d = c & 0xff;
621 if (d > d0 + 1 && d[-2] == 0x83
622 && 0x6e <= d[-1] && d[-1] <= 0x7a && (b = handaku[d[-1] - 0x6e])) {
624 if (ch) { ch[-1]++; s_++; }
627 *d++ = c >> 8; *d = c & 0xff;
631 *d++ = c >> 8; *d = c & 0xff;
636 if ((s + 1) < e && 0x40 <= *(s + 1) && *(s + 1) <= 0xfc) {
637 unsigned char c1 = *s++, c2 = *s, c3 = 0;
638 if (0x81 <= c1 && c1 <= 0x87) {
660 if (0x43 <= c2 && c2 <= 0x7e && (c3 = symbol[c2 - 0x43])) {
663 }
else if (0x7f <= c2 && c2 <= 0x97 && (c3 = symbol[c2 - 0x44])) {
675 if (0x4f <= c2 && c2 <= 0x58) {
678 }
else if (0x60 <= c2 && c2 <= 0x79) {
681 }
else if (0x81 <= c2 && c2 <= 0x9a) {
684 }
else if (0x9f <= c2 && c2 <= 0xf1) {
693 if (0x40 <= c2 && c2 <= 0x96) {
721 unsigned char c = *s;
747 *d = (
'A' <= c) ? c + 0x20 : c;
751 *d = (c <=
'Z') ? c + 0x20 : c;
770 if (cp) { *cp++ = ctype; }
772 *ch++ = (int16_t)(s + 1 - s_);
774 while (++d_ < d) { *ch++ = 0; }
788 const unsigned char *s, *s_, *e;
789 unsigned char *d, *d0, *d_;
791 size_t size = nstr->
orig_blen, length = 0;
796 d0 = (
unsigned char *) nstr->
norm;
814 cp = ctypes = nstr->
ctypes;
815 e = (
unsigned char *)nstr->
orig + size;
816 for (s = s_ = (
unsigned char *) nstr->
orig, d = d_ = d0; s < e; s++) {
817 unsigned char c = *s;
843 *d = (
'A' <= c) ? c + 0x20 : c;
847 *d = (c <=
'Z') ? c + 0x20 : c;
865 if (cp) { *cp++ = ctype; }
867 *ch++ = (int16_t)(s + 1 - s_);
869 while (++d_ < d) { *ch++ = 0; }
884 const unsigned char *s, *s_, *e;
885 unsigned char *d, *d0, *d_;
887 size_t size = nstr->
orig_blen, length = 0;
892 d0 = (
unsigned char *) nstr->
norm;
910 cp = ctypes = nstr->
ctypes;
911 e = (
unsigned char *)nstr->
orig + size;
912 for (s = s_ = (
unsigned char *) nstr->
orig, d = d_ = d0; s < e; s++) {
913 unsigned char c = *s;
939 *d = (
'A' <= c) ? c + 0x20 : c;
943 *d = (c <=
'Z') ? c + 0x20 : c;
955 if (c == 0x8a || c == 0x8c || c == 0x8e) {
964 if (c == 0x9a || c == 0x9c || c == 0x9e || c == 0x9f) {
965 *d = (c == 0x9f) ? c + 0x60 : c;
977 *d = (c == 0xd7 || c == 0xdf) ? c : c + 0x20;
995 if (cp) { *cp++ = ctype; }
997 *ch++ = (int16_t)(s + 1 - s_);
999 while (++d_ < d) { *ch++ = 0; }
1005 nstr->
norm_blen = (size_t)(d - (
unsigned char *)nstr->
norm);
1013 const unsigned char *s, *s_, *e;
1014 unsigned char *d, *d0, *d_;
1016 size_t size = strlen(nstr->
orig), length = 0;
1021 d0 = (
unsigned char *) nstr->
norm;
1039 cp = ctypes = nstr->
ctypes;
1040 e = (
unsigned char *)nstr->
orig + size;
1041 for (s = s_ = (
unsigned char *) nstr->
orig, d = d_ = d0; s < e; s++) {
1042 unsigned char c = *s;
1068 *d = (
'A' <= c) ? c + 0x20 : c;
1072 *d = (c <=
'Z') ? c + 0x20 : c;
1113 if (cp) { *cp++ = ctype; }
1115 *ch++ = (int16_t)(s + 1 - s_);
1117 while (++d_ < d) { *ch++ = 0; }
1123 nstr->
norm_blen = (size_t)(d - (
unsigned char *)nstr->
norm);
1143 memcpy(nstr->
norm, str, str_len);
1144 nstr->
norm[str_len] =
'\0';
1160 for (i = 0; i < str_len; i++) {
1162 c = (
unsigned char) str[i];
1163 f = ((c >= 0xa1U && c <= 0xfeU) || c == 0x8eU ? 2 : (c == 0x8fU ? 3 : 1)
1173 for (i = 0; i < str_len; i++) {
1175 c = (
unsigned char) str[i];
1176 f = (c >= 0x81U && ((c <= 0x9fU) || (c >= 0xe0U && c <= 0xfcU)) ? 2 : 1);
1185 for (i = 0; i < str_len; i++) {
1187 c = (
unsigned char) str[i];
1188 f = (c & 0x80U ? (c & 0x20U ? (c & 0x10U ? 4 : 3)
1199 for (i = 0; i < str_len; i++) {
1215 if (!str || !str_len) {
return NULL; }
1218 return grn_fakenstr_open(ctx, str, str_len, encoding, flags);
1235 rc = normalize_euc(ctx, nstr);
1238 #ifdef GRN_WITH_NFKC
1239 rc = normalize_utf8(ctx, nstr);
1241 rc = normalize_none(ctx, nstr);
1245 rc = normalize_sjis(ctx, nstr);
1248 rc = normalize_latin1(ctx, nstr);
1251 rc = normalize_koi8r(ctx, nstr);
1254 rc = normalize_none(ctx, nstr);
1284 static const char *grn_enc_string[] = {
1297 if (enc < (
sizeof(grn_enc_string) /
sizeof(
char *))) {
1298 return grn_enc_string[enc];
1308 int i =
sizeof(grn_enc_string) /
sizeof(grn_enc_string[0]);
1310 if (!strcmp(str, grn_enc_string[i])) {
1321 const char *p = NULL;
1322 for (len = 0; ; len++) {
1329 if (last) { *last = p; }
1336 const unsigned char *s = (
const unsigned char *) str;
1337 if (!s) {
return 0; }
1347 if (encoding ==
GRN_ENC_SJIS && s[1] == 0x40) {
return 2; }
1353 if (encoding ==
GRN_ENC_UTF8 && s[1] == 0x80 && s[2] == 0x80) {
return 3; }
1362 grn_atoi8(
const char *nptr,
const char *end,
const char **rest)
1364 const char *p = nptr;
1365 int8_t v = 0, t, n = 0, o = 0;
1366 if (p < end && *p ==
'-') {
1371 while (p < end && *p >=
'0' && *p <=
'9') {
1372 t = v * 10 - (*p -
'0');
1373 if (t > v || (!n && t ==
INT8_MIN)) { v = 0;
break; }
1378 if (rest) { *rest = o ? nptr : p; }
1386 while (nptr < end && *nptr >=
'0' && *nptr <=
'9') {
1387 t = v * 10 + (*nptr -
'0');
1388 if (t < v) { v = 0;
break; }
1392 if (rest) { *rest = nptr; }
1399 const char *p = nptr;
1400 int16_t v = 0, t, n = 0, o = 0;
1401 if (p < end && *p ==
'-') {
1406 while (p < end && *p >=
'0' && *p <=
'9') {
1407 t = v * 10 - (*p -
'0');
1408 if (t > v || (!n && t ==
INT16_MIN)) { v = 0;
break; }
1413 if (rest) { *rest = o ? nptr : p; }
1421 while (nptr < end && *nptr >=
'0' && *nptr <=
'9') {
1422 t = v * 10 + (*nptr -
'0');
1423 if (t < v) { v = 0;
break; }
1427 if (rest) { *rest = nptr; }
1432 grn_atoi(
const char *nptr,
const char *end,
const char **rest)
1434 const char *p = nptr;
1435 int v = 0, t, n = 0, o = 0;
1436 if (p < end && *p ==
'-') {
1441 while (p < end && *p >=
'0' && *p <=
'9') {
1442 t = v * 10 - (*p -
'0');
1443 if (t > v || (!n && t ==
INT32_MIN)) { v = 0;
break; }
1448 if (rest) { *rest = o ? nptr : p; }
1453 grn_atoui(
const char *nptr,
const char *end,
const char **rest)
1455 unsigned int v = 0, t;
1456 while (nptr < end && *nptr >=
'0' && *nptr <=
'9') {
1457 t = v * 10 + (*nptr -
'0');
1458 if (t < v) { v = 0;
break; }
1462 if (rest) { *rest = nptr; }
1467 grn_atoll(
const char *nptr,
const char *end,
const char **rest)
1470 const char *p = nptr;
1473 if (p < end && *p ==
'-') {
1478 while (p < end && *p >=
'0' && *p <=
'9') {
1479 t = v * 10 + (*p -
'0');
1480 if (t < v) { v = 0;
break; }
1485 if (rest) { *rest = o ? nptr : p; }
1490 grn_htoui(
const char *nptr,
const char *end,
const char **rest)
1492 unsigned int v = 0, t;
1493 while (nptr < end) {
1505 t = v * 16 + (*nptr++ -
'0');
1513 t = v * 16 + (*nptr++ -
'a') + 10;
1521 t = v * 16 + (*nptr++ -
'A') + 10;
1526 if (t < v) { v = 0;
goto exit; }
1530 if (rest) { *rest = nptr; }
1537 static const char *hex =
"0123456789ABCDEF";
1540 *p-- = hex[i & 0xf];
1556 *p++ = (-(i % 10)) +
'0';
1563 *p++ = i % 10 +
'0';
1564 }
while ((i /= 10) > 0);
1565 if (rest) { *rest = p; }
1566 for (p--; q < p; q++, p--) {
1583 *p++ = (-(i % 10)) +
'0';
1591 *q-- = i % 10 +
'0';
1592 }
while ((i /= 10) > 0);
1609 *p++ = (-(i % 10)) +
'0';
1616 *p++ = i % 10 +
'0';
1617 }
while ((i /= 10) > 0);
1618 if (rest) { *rest = p; }
1619 for (p--; q < p; q++, p--) {
1635 *p++ = i % 10 +
'0';
1636 }
while ((i /= 10) > 0);
1637 if (rest) { *rest = p; }
1638 for (p--; q < p; q++, p--) {
1647 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(i) & 0x3f])
1650 (((b) < '+' || 'z' < (b)) ? 0xff : "\x3e\xff\xff\xff\x3f\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\xff\xff\xff\xff\xff\xff\xff\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\xff\xff\xff\xff\xff\xff\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33"[(b) - '+'])
1652 #define MASK 0x34d34d34
1658 *p++ =
I2B(
id >> 24);
1659 *p++ =
I2B(
id >> 18);
1660 *p++ =
I2B(
id >> 12);
1661 *p++ =
I2B(
id >> 6);
1674 if ((i =
B2I(c)) == 0xff) {
return 0; }
1680 #define I2B32H(i) ("0123456789ABCDEFGHIJKLMNOPQRSTUV"[(i) & 0x1f])
1685 uint64_t u = (uint64_t)i + 0x8000000000000000ULL;
1705 char lb = (i >> 59) & 0x10;
1706 i += 0x8000000000000000ULL;
1707 *p++ = lb +
I2B32H(i >> 60);
1733 case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
1734 case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
1744 }
else if ((int64_t)INT32_MAX < int64 && int64 <= (int64_t)
UINT32_MAX) {
1751 }
else if (rest_char ==
'.' || rest_char ==
'e' || rest_char ==
'E' ||
1752 (rest_char >=
'0' && rest_char <=
'9')) {
1756 d = strtod(p, &rest_float);
1757 if (!errno && rest_float == end) {
1776 grn_str_tok(
const char *str,
size_t str_len,
char delim,
const char **tokbuf,
int buf_size,
const char **rest)
1778 const char **tok = tokbuf, **tok_end = tokbuf + buf_size;
1780 const char *str_end = str + str_len;
1782 if (str == str_end) {
1786 if (delim == *str) {
1789 if (tok == tok_end) {
break; }
1793 if (rest) { *rest = str; }
1794 return tok - tokbuf;
1799 int argc,
char *
const argv[],
int i,
const char *optvalue)
1818 *o->
arg = (
char *)optvalue;
1819 }
else if (++i < argc) {
1833 for (i = 1; i < argc; i++) {
1834 const char * v = argv[
i];
1843 for (eq = v; *eq !=
'\0' && *eq !=
'='; eq++) {}
1845 for (o = opts; o->
opt !=
'\0' || o->
longopt != NULL; o++) {
1847 !memcmp(v, o->
longopt, len)) {
1848 i = op_getopt_flag(flags, o, argc, argv, i,
1849 (*eq ==
'\0' ? NULL : eq + 1));
1851 fprintf(stderr,
"%s: option '--%s' needs argument.\n", argv[0], o->
longopt);
1858 if (!found) {
goto exit; }
1861 for (p = v; *p; p++) {
1863 for (o = opts; o->
opt !=
'\0' || o->
longopt != NULL; o++) {
1864 if (o->
opt && *p == o->
opt) {
1865 i = op_getopt_flag(flags, o, argc, argv, i, NULL);
1867 fprintf(stderr,
"%s: option '-%c' needs argument.\n", argv[0], *p);
1874 if (!found) {
goto exit; }
1883 fprintf(stderr,
"%s: cannot recognize option '%s'.\n", argv[0], argv[i]);
1887 #define UNIT_SIZE (1 << 12)
1888 #define UNIT_MASK (UNIT_SIZE - 1)
1896 unsigned int rounded_newsize;
1897 newsize += grn_bulk_margin_size + 1;
1901 newsize = rounded_newsize;
1902 head = buf->
u.
b.head - (buf->
u.
b.head ? grn_bulk_margin_size : 0);
1906 buf->
u.
b.tail = head + newsize;
1911 newsize = rounded_newsize;
1916 buf->
u.
b.tail = head + newsize;
1939 memcpy(curr, str, len);
1946 const char *str,
unsigned int from,
unsigned int len)
1974 grn_bulk_space_clear(
grn_ctx *ctx,
grn_obj *buf,
unsigned int len)
1988 if ((bulk->
u.
b.tail - bulk->
u.
b.head) < len) {
1989 return grn_bulk_space_clear(ctx, bulk, len);
1991 bulk->
u.
b.curr = bulk->
u.
b.head + len;
1995 return grn_bulk_space_clear(ctx, bulk, len);
2010 if (
grn_itoa(i, curr, tail, &curr)) {
2072 #define DIGIT_NUMBER 15
2075 len = sprintf(curr,
"%#.*g", DIGIT_NUMBER, d);
2077 if (curr[len - 1] ==
'.') {
2083 if ((p = strchr(curr,
'e'))) {
2084 for (q = p; *(q - 2) !=
'.' && *(q - 1) ==
'0'; q--) { len--; }
2085 memmove(q, p, curr + len - q);
2087 for (q = curr + len; *(q - 2) !=
'.' && *(q - 1) ==
'0'; q--) { len--; }
2100 #ifdef HAVE_FPCLASSIFY
2101 switch (fpclassify(d)) {
2114 if (d != 0 && ((d / 2.0) == d)) {
2172 for (e = s + len; s < e; s += l) {
2197 case '\x00':
case '\x01':
case '\x02':
case '\x03':
case '\x04':
case '\x05':
2198 case '\x06':
case '\x07':
case '\x0b':
case '\x0e':
case '\x0f':
case '\x10':
2199 case '\x11':
case '\x12':
case '\x13':
case '\x14':
case '\x15':
case '\x16':
2200 case '\x17':
case '\x18':
case '\x19':
case '\x1a':
case '\x1b':
case '\x1c':
2201 case '\x1d':
case '\x1e':
case '\x1f':
case '\x7f':
2214 }
else if (l == 3) {
2215 if (*s ==
'\xe2' && *(s + 1) ==
'\x80') {
2244 for (e = s + len; s < e; s += l) {
2270 #define TOK_ESC (0x80)
2278 for (p = s; p < e; p += len) {
2286 if (*p ==
' ') {
continue; }
2310 if (*p ==
' ') {
goto exit; }
2399 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2400 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2401 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1,
2402 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
2403 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2404 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2405 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2406 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
2412 const char *e, c =
'%';
2413 for (e = s + len; s < e; s++) {
2414 if (*s < 0 || urlenc_tbl[(
int)*s]) {
2427 static const char *weekdays[7] = {
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"};
2428 static const char *months[12] = {
2429 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
2430 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"};
2437 #ifdef HAVE_GMTIME_R
2440 t = gmtime_r(&tsec, &tm);
2477 buf->
u.
b.head = NULL;
2478 buf->
u.
b.curr = NULL;
2479 buf->
u.
b.tail = NULL;
2488 char *s = *str, *e = *str_end;
2489 for (i = 0; s < e; i++, s += l) {
2490 if (i == start) { *str = s; }
2548 grn_text_atoj(ctx, bulk, (
grn_obj *)a->
next, *idp);
2553 grn_text_atoj(ctx, bulk, a->
obj,
id);
2684 for (j = 0; j < ncolumns; j++) {
2713 for (j = 0; j < ncolumns; j++) {
2715 grn_text_atoj(ctx, bulk, columns[j],
id);
2749 for (j = 0; j < ncolumns; j++) {
2779 for (j = 0; j < ncolumns; j++) {
2851 "cannot print GRN_VECTOR using grn_obj_format");
2858 for (i = 0; i < n; i++) {
2860 unsigned int weight, length;
2865 &_value, &weight, &domain);
2880 "cannot print GRN_PVECTOR using grn_obj_format");
2885 for (i = 0; i < n; i++) {
2905 if (!tc) {
ERRCLR(ctx); }
2911 for (j = 0; j < ncolumns; j++) {
2943 for (j = 0; j < ncolumns; j++) {
2945 grn_text_atoj(ctx, bulk, columns[j],
id);
2983 }
else if (*p ==
'%' && p + 3 <= e) {
2985 unsigned int c =
grn_htoui(p + 1, p + 3, &r);
3004 const char *delimiters)
3008 const char *delimiter;
3009 for (delimiter = delimiters; *delimiter; delimiter++) {
3010 if (*p == *delimiter) {
3015 if (found_delimiter) {
3023 }
else if (*p ==
'%' && p + 3 <= e) {
3025 unsigned int c =
grn_htoui(p + 1, p + 3, &r);
3044 char *buf,
size_t buf_len)
3046 char *b = buf, *be = buf + buf_len - 1;
3047 const char *p = path, *pe = path + path_len, *pc;
3049 if (buf_len < 2) {
return; }
3052 for (pc = p; pc < pe && *pc !=
'/'; pc++) {}
3054 if (pc == p + 2 && *(p + 1) ==
'.') {
3057 for (b -= 2; *b !=
'/' && b >= buf; b--) {}
3065 }
else if (pc == p + 1) {
3071 if (be - b >= pc - p) {
3072 memcpy(b, p, (pc - p));
3075 if (p < pe && *pc == '/' && be > b) {
3105 for (; s; s--, v++) {