20 #define BEG(no) (regs->beg[(no)])
21 #define END(no) (regs->end[(no)])
30 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
32 #undef rb_str_new_cstr
33 #undef rb_tainted_str_new_cstr
34 #undef rb_usascii_str_new_cstr
35 #undef rb_external_str_new_cstr
36 #undef rb_locale_str_new_cstr
41 #undef rb_tainted_str_new2
42 #undef rb_usascii_str_new2
43 #undef rb_str_dup_frozen
44 #undef rb_str_buf_new_cstr
45 #undef rb_str_buf_new2
46 #undef rb_str_buf_cat2
54 #define RUBY_MAX_CHAR_LEN 16
55 #define STR_TMPLOCK FL_USER7
56 #define STR_NOEMBED FL_USER1
57 #define STR_SHARED FL_USER2
58 #define STR_ASSOC FL_USER3
59 #define STR_SHARED_P(s) FL_ALL((s), STR_NOEMBED|ELTS_SHARED)
60 #define STR_ASSOC_P(s) FL_ALL((s), STR_NOEMBED|STR_ASSOC)
61 #define STR_NOCAPA (STR_NOEMBED|ELTS_SHARED|STR_ASSOC)
62 #define STR_NOCAPA_P(s) (FL_TEST((s),STR_NOEMBED) && FL_ANY((s),ELTS_SHARED|STR_ASSOC))
63 #define STR_UNSET_NOCAPA(s) do {\
64 if (FL_TEST((s),STR_NOEMBED)) FL_UNSET((s),(ELTS_SHARED|STR_ASSOC));\
68 #define STR_SET_NOEMBED(str) do {\
69 FL_SET((str), STR_NOEMBED);\
70 STR_SET_EMBED_LEN((str), 0);\
72 #define STR_SET_EMBED(str) FL_UNSET((str), STR_NOEMBED)
73 #define STR_EMBED_P(str) (!FL_TEST((str), STR_NOEMBED))
74 #define STR_SET_EMBED_LEN(str, n) do { \
76 RBASIC(str)->flags &= ~RSTRING_EMBED_LEN_MASK;\
77 RBASIC(str)->flags |= (tmp_n) << RSTRING_EMBED_LEN_SHIFT;\
80 #define STR_SET_LEN(str, n) do { \
81 if (STR_EMBED_P(str)) {\
82 STR_SET_EMBED_LEN((str), (n));\
85 RSTRING(str)->as.heap.len = (n);\
89 #define STR_DEC_LEN(str) do {\
90 if (STR_EMBED_P(str)) {\
91 long n = RSTRING_LEN(str);\
93 STR_SET_EMBED_LEN((str), n);\
96 RSTRING(str)->as.heap.len--;\
100 #define RESIZE_CAPA(str,capacity) do {\
101 if (STR_EMBED_P(str)) {\
102 if ((capacity) > RSTRING_EMBED_LEN_MAX) {\
103 char *tmp = ALLOC_N(char, (capacity)+1);\
104 memcpy(tmp, RSTRING_PTR(str), RSTRING_LEN(str));\
105 RSTRING(str)->as.heap.ptr = tmp;\
106 RSTRING(str)->as.heap.len = RSTRING_LEN(str);\
107 STR_SET_NOEMBED(str);\
108 RSTRING(str)->as.heap.aux.capa = (capacity);\
112 REALLOC_N(RSTRING(str)->as.heap.ptr, char, (capacity)+1);\
113 if (!STR_NOCAPA_P(str))\
114 RSTRING(str)->as.heap.aux.capa = (capacity);\
118 #define is_ascii_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT)
119 #define is_broken_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN)
121 #define STR_ENC_GET(str) rb_enc_from_index(ENCODING_GET(str))
143 static inline const char *
146 #if SIZEOF_VALUE == 8
147 # define NONASCII_MASK 0x8080808080808080ULL
148 #elif SIZEOF_VALUE == 4
149 # define NONASCII_MASK 0x80808080UL
152 if ((
int)
sizeof(
VALUE) * 2 < e - p) {
155 s = (
const VALUE*)(~lowbits & ((
VALUE)p + lowbits));
156 while (p < (
const char *)s) {
163 if (*s & NONASCII_MASK) {
183 const char *e = p +
len;
363 return RSTRING(str)->as.heap.len;
366 return RSTRING(str)->as.heap.aux.capa;
376 str->as.heap.ptr = 0;
377 str->as.heap.len = 0;
378 str->as.heap.aux.capa = 0;
441 #define rb_str_new2 rb_str_new_cstr
452 #define rb_usascii_str_new2 rb_usascii_str_new_cstr
473 #define rb_tainted_str_new2 rb_tainted_str_new_cstr
482 const unsigned char *sp;
486 if (from == to)
return str;
511 len = len < 2 ? 2 : len * 2;
615 RSTRING(str2)->as.heap.aux.shared = str;
645 #define rb_str_new3 rb_str_new_shared
660 RSTRING(str2)->as.heap.aux.shared = shared;
664 RSTRING(str)->as.heap.aux.shared = str2;
682 if ((ofs > 0) || (klass !=
RBASIC(str)->klass) ||
686 RSTRING(str)->as.heap.ptr += ofs;
687 RSTRING(str)->as.heap.len -= ofs;
700 str = str_new4(klass, orig);
702 RSTRING(str)->as.heap.aux.shared = assoc;
705 str = str_new4(klass, orig);
712 #define rb_str_new4 rb_str_new_frozen
722 #define rb_str_new5 rb_str_new_with_class
725 str_new_empty(
VALUE str)
733 #define STR_BUF_MIN_SIZE 128
744 RSTRING(str)->as.heap.aux.capa = capa;
746 RSTRING(str)->as.heap.ptr[0] =
'\0';
764 #define rb_str_buf_new2 rb_str_buf_new_cstr
800 return RSTRING(str)->as.heap.aux.capa;
820 if (str == str2)
return;
839 RSTRING(str)->as.heap.aux.shared =
RSTRING(str2)->as.heap.aux.shared;
885 RSTRING(str)->as.heap.aux.shared = shared;
928 if (argc > 0 &&
rb_scan_args(argc, argv,
"01", &orig) == 1)
973 for (c=0; p<e; c++) {
1023 for (c=0; p<e; c++) {
1041 #ifdef NONASCII_MASK
1042 #define is_utf8_lead_byte(c) (((c)&0xC0) != 0x80)
1057 count_utf8_lead_bytes_with_word(
const VALUE *s)
1064 d &= NONASCII_MASK >> 7;
1069 #if SIZEOF_VALUE == 8
1088 #ifdef NONASCII_MASK
1093 if ((
int)
sizeof(
VALUE) * 2 < e - p) {
1096 s = (
const VALUE*)(~lowbits & ((
VALUE)p + lowbits));
1098 while (p < (
const char *)s) {
1099 if (is_utf8_lead_byte(*p)) len++;
1103 len += count_utf8_lead_bytes_with_word(s);
1106 p = (
const char *)s;
1109 if (is_utf8_lead_byte(*p)) len++;
1237 while (n <= len/2) {
1238 memcpy(ptr2 + n, ptr2, n);
1241 memcpy(ptr2 + n, ptr2, len-n);
1301 long capa = len + expand;
1303 if (len > capa) len = capa;
1304 ptr =
ALLOC_N(
char, capa + 1);
1311 RSTRING(str)->as.heap.ptr = ptr;
1313 RSTRING(str)->as.heap.aux.capa = capa;
1316 #define str_make_independent(str) str_make_independent_expand((str), 0L)
1335 else if (expand > 0) {
1337 long capa = len + expand;
1340 RSTRING(str)->as.heap.aux.capa = capa;
1366 RSTRING(str)->as.heap.ptr = 0;
1367 RSTRING(str)->as.heap.len = 0;
1385 assoc =
RSTRING(assoc)->as.heap.aux.shared;
1407 return RSTRING(str)->as.heap.aux.shared;
1437 if (!s || memchr(s, 0, len)) {
1483 const char *p2, *e2;
1486 while (p < e && 0 < nth) {
1512 while (p < e && nth--) {
1544 const char *pp =
str_nth(p, e, nth, enc, singlebyte);
1545 if (!pp)
return e -
p;
1556 #ifdef NONASCII_MASK
1558 str_utf8_nth(
const char *
p,
const char *e,
long *nthp)
1564 s = (
const VALUE*)(~lowbits & ((
VALUE)p + lowbits));
1566 while (p < (
const char *)s) {
1567 if (is_utf8_lead_byte(*p)) nth--;
1571 nth -= count_utf8_lead_bytes_with_word(s);
1573 }
while (s < t && (
int)
sizeof(
VALUE) <= nth);
1577 if (is_utf8_lead_byte(*p)) {
1578 if (nth == 0)
break;
1588 str_utf8_offset(
const char *p,
const char *e,
long nth)
1590 const char *pp = str_utf8_nth(p, e, &nth);
1634 if (len < 0)
return Qnil;
1642 if (beg < 0)
return Qnil;
1655 if (len > -beg) len = -beg;
1660 if (!p)
return Qnil;
1662 if (!p)
return Qnil;
1668 if (beg < 0)
return Qnil;
1678 #ifdef NONASCII_MASK
1681 p = str_utf8_nth(s, e, &beg);
1682 if (beg > 0)
return Qnil;
1683 len = str_utf8_offset(p, e, len);
1689 p = s + beg * char_sz;
1693 else if (len * char_sz > e - p)
1698 else if ((p =
str_nth_len(s, e, &beg, enc)) == e) {
1699 if (beg > 0)
return Qnil;
1732 #define rb_str_dup_frozen rb_str_new_frozen
1764 rb_bug(
"probable buffer overflow: %ld for %ld", len, capa);
1794 char *ptr =
RSTRING(str)->as.heap.ptr;
1796 if (slen > len) slen =
len;
1797 if (slen > 0)
MEMCPY(
RSTRING(str)->as.ary, ptr,
char, slen);
1800 if (independent)
xfree(ptr);
1803 else if (!independent) {
1806 else if (slen < len || slen - len > 1024) {
1821 long capa, total, off = -1;
1827 if (len == 0)
return 0;
1836 capa =
RSTRING(str)->as.heap.aux.capa;
1842 if (capa <= total) {
1843 while (total > capa) {
1845 capa = (total + 4095) / 4096;
1848 capa = (capa + 1) * 2;
1862 #define str_buf_cat2(str, ptr) str_buf_cat((str), (ptr), strlen(ptr))
1867 if (len == 0)
return str;
1889 p =
RSTRING(str)->as.heap.ptr;
1890 memcpy(p +
RSTRING(str)->as.heap.len, ptr, len);
1907 int ptr_encindex,
int ptr_cr,
int *ptr_cr_ret)
1915 if (str_encindex == ptr_encindex) {
1945 *ptr_cr_ret = ptr_cr;
1947 if (str_encindex != ptr_encindex &&
1957 res_encindex = str_encindex;
1962 res_encindex = str_encindex;
1966 res_encindex = ptr_encindex;
1971 res_encindex = str_encindex;
1978 res_encindex = str_encindex;
2011 unsigned int c = (
unsigned char)*ptr;
2101 char buf[1] = {(char)code};
2197 #define lesser(a,b) (((a)>(b))?(b):(a))
2209 if (idx1 == idx2)
return TRUE;
2228 const char *ptr1, *ptr2;
2231 if (str1 == str2)
return 0;
2234 if (ptr1 == ptr2 || (retval =
memcmp(ptr1, ptr2,
lesser(len1, len2))) == 0) {
2243 if (len1 > len2)
return 1;
2246 if (retval > 0)
return 1;
2255 const char *ptr1, *ptr2;
2261 if (
memcmp(ptr1, ptr2, len) == 0)
2277 if (str1 == str2)
return Qtrue;
2297 if (str1 == str2)
return Qtrue;
2370 char *p1, *p1end, *p2, *p2end;
2381 while (p1 < p1end && p2 < p2end) {
2383 unsigned int c1 =
TOUPPER(*p1 & 0xff);
2384 unsigned int c2 =
TOUPPER(*p2 & 0xff);
2386 return INT2FIX(c1 < c2 ? -1 : 1);
2393 while (p1 < p1end && p2 < p2end) {
2397 if (0 <= c1 && 0 <= c2) {
2401 return INT2FIX(c1 < c2 ? -1 : 1);
2407 len = l1 < l2 ? l1 : l2;
2410 return INT2FIX(r < 0 ? -1 : 1);
2412 return INT2FIX(l1 < l2 ? -1 : 1);
2439 if (offset < 0)
return -1;
2441 if (len - offset < slen)
return -1;
2448 if (slen == 0)
return offset;
2456 if (pos < 0)
return pos;
2458 if (t == s + pos)
break;
2459 if ((len -= t - s) <= 0)
return -1;
2463 return pos + offset;
2491 if (
rb_scan_args(argc, argv,
"11", &sub, &initpos) == 2) {
2507 switch (
TYPE(sub)) {
2535 if (pos == -1)
return Qnil;
2543 char *s, *sbeg, *e, *t;
2554 if (len < slen)
return -1;
2555 if (len - pos < slen) {
2565 s =
str_nth(sbeg, e, pos, enc, singlebyte);
2567 if (
memcmp(s, t, slen) == 0) {
2570 if (pos == 0)
break;
2604 if (
rb_scan_args(argc, argv,
"11", &sub, &vpos) == 2) {
2615 if (pos > len) pos =
len;
2621 switch (
TYPE(sub)) {
2631 if (pos >= 0)
return LONG2NUM(pos);
2647 if (pos >= 0)
return LONG2NUM(pos);
2742 for (i = len-1; 0 <= i && (
unsigned char)p[i] == 0xff; i--)
2746 ++((
unsigned char*)p)[
i];
2754 memset(p+l, 0xff, len-l);
2760 for (len2 = len-1; 0 < len2; len2--) {
2765 memset(p+len2+1, 0xff, len-(len2+1));
2776 for (i = len-1; 0 <= i && (
unsigned char)p[i] == 0; i--)
2780 --((
unsigned char*)p)[
i];
2788 memset(p+l, 0, len-l);
2794 for (len2 = len-1; 0 < len2; len2--) {
2799 memset(p+len2+1, 0, len-(len2+1));
2830 MEMCPY(save, p,
char, len);
2837 MEMCPY(p, save,
char, len);
2840 MEMCPY(save, p,
char, len);
2845 MEMCPY(p, save,
char, len);
2850 MEMCPY(p, save,
char, len);
2860 MEMCPY(carry, p,
char, len);
2864 MEMCPY(carry, p,
char, len);
2900 char *sbeg, *s, *e, *last_alnum = 0;
2904 long carry_pos = 0, carry_len = 1;
2936 carry_pos = s - sbeg;
2952 MEMCPY(carry, s,
char, l);
2955 carry_pos = s - sbeg;
3022 VALUE end, exclusive;
3023 VALUE current, after_end;
3030 excl =
RTEST(exclusive);
3040 if (c > e || (excl && c == e))
return beg;
3043 if (!excl && c == e)
break;
3045 if (excl && c == e)
break;
3074 if (excl && bi == ei)
break;
3095 if (n > 0 || (excl && n == 0))
return beg;
3104 if (
NIL_P(next))
break;
3131 switch (
TYPE(indx)) {
3243 if (len > olen) len = olen;
3251 memmove(ptr, oldptr + len, nlen);
3257 RSTRING(str)->as.heap.len = nlen;
3322 if (slen < len || slen < beg + len) {
3351 long start, end,
len;
3389 switch (
TYPE(indx)) {
3525 if (argc < 1 || 2 < argc) {
3528 for (i=0; i<
argc; i++) {
3533 if (!
NIL_P(result)) {
3545 switch (
TYPE(pat)) {
3590 else if (argc == 2) {
3615 if (iter || !
NIL_P(hash)) {
3663 memmove(p + beg0 + rlen, p + beg0 + plen, len - beg0 - plen);
3665 memcpy(p + beg0, rp, rlen);
3734 long offset, blen, slen,
len,
last;
3760 if (bang)
return Qnil;
3781 if (iter || !
NIL_P(hash)) {
3817 offset = end0 +
len;
3856 return str_gsub(argc, argv, str, 1);
3906 return str_gsub(argc, argv, str, 0);
3925 if (str == str2)
return str;
4022 if (beg > n || len < 0)
return Qnil;
4025 if (beg < 0)
return Qnil;
4055 switch (
TYPE(indx)) {
4152 if (clen > 1 || (*s & 0x80)) single = 0;
4162 if (clen > 1 || (*s & 0x80)) single = 0;
4239 if (i == -1)
return Qfalse;
4270 if (argc == 0) base = 10;
4334 #define CHAR_ESC_LEN 13
4349 else if (c < 0x10000) {
4385 const char *
p, *pend, *prev;
4403 const unsigned char *q = (
const unsigned char *)p;
4404 if (q[0] == 0xFE && q[1] == 0xFF)
4406 else if (q[0] == 0xFF && q[1] == 0xFE)
4411 else if (enc == utf32) {
4412 const unsigned char *q = (
const unsigned char *)p;
4413 if (q[0] == 0 && q[1] == 0 && q[2] == 0xFE && q[3] == 0xFF)
4415 else if (q[3] == 0 && q[2] == 0 && q[1] == 0xFE && q[0] == 0xFF)
4426 if (p > prev)
str_buf_cat(result, prev, p - prev);
4429 n = (int)(pend - p);
4440 if ((asciicompat || unicode_p) &&
4441 (c ==
'"'|| c ==
'\\' ||
4446 (cc ==
'$' || cc ==
'@' || cc ==
'{'))))) {
4447 if (p - n > prev)
str_buf_cat(result, prev, p - n - prev);
4449 if (asciicompat || enc == resenc) {
4455 case '\n': cc =
'n';
break;
4456 case '\r': cc =
'r';
break;
4457 case '\t': cc =
't';
break;
4458 case '\f': cc =
'f';
break;
4459 case '\013': cc =
'v';
break;
4460 case '\010': cc =
'b';
break;
4461 case '\007': cc =
'a';
break;
4462 case 033: cc =
'e';
break;
4463 default: cc = 0;
break;
4466 if (p - n > prev)
str_buf_cat(result, prev, p - n - prev);
4478 if (p - n > prev)
str_buf_cat(result, prev, p - n - prev);
4484 if (p > prev)
str_buf_cat(result, prev, p - prev);
4491 #define IS_EVSTR(p,e) ((p) < (e) && (*(p) == '$' || *(p) == '@' || *(p) == '{'))
4506 const char *
p, *pend;
4514 unsigned char c = *p++;
4516 case '"':
case '\\':
4517 case '\n':
case '\r':
4518 case '\t':
case '\f':
4519 case '\013':
case '\010':
case '\007':
case '\033':
4536 while (cc >>= 4) len++;
4558 unsigned char c = *p++;
4560 if (c ==
'"' || c ==
'\\') {
4564 else if (c ==
'#') {
4565 if (
IS_EVSTR(p, pend)) *q++ =
'\\';
4568 else if (c ==
'\n') {
4572 else if (c ==
'\r') {
4576 else if (c ==
'\t') {
4580 else if (c ==
'\f') {
4584 else if (c ==
'\013') {
4588 else if (c ==
'\010') {
4592 else if (c ==
'\007') {
4596 else if (c ==
'\033') {
4622 snprintf(q, qend-q,
".force_encoding(\"%s\")", enc->
name);
4665 unsigned int c = *(
unsigned char*)s;
4668 *s =
'A' + (c -
'a');
4680 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
4682 *s =
'A' + (c -
'a');
4699 if (modify)
return str;
4747 unsigned int c = *(
unsigned char*)s;
4750 *s =
'a' + (c -
'A');
4763 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
4765 *s =
'a' + (c -
'A');
4782 if (modify)
return str;
4852 if (modify)
return str;
4916 if (modify)
return str;
4956 if (t->
p == t->
pend)
return -1;
4957 if (t->
p < t->
pend - 1 && *t->
p ==
'\\') {
4962 if (t->
p < t->
pend - 1 && *t->
p ==
'-') {
4964 if (t->
p < t->
pend) {
4968 if (t->
now < 0x80 && c < 0x80) {
4970 "invalid range \"%c-%c\" in string transliteration",
4984 else if (++t->
now < t->
max) {
4999 const unsigned int errc = -1;
5000 unsigned int trans[256];
5002 struct tr trsrc, trrepl;
5004 unsigned int c, c0,
last = 0;
5005 int modify = 0,
i, l;
5011 #define CHECK_IF_ASCII(c) \
5012 (void)((cr == ENC_CODERANGE_7BIT && !rb_isascii(c)) ? \
5013 (cr = ENC_CODERANGE_VALID) : 0)
5034 trsrc.
p + l < trsrc.
pend) {
5040 trsrc.
gen = trrepl.
gen = 0;
5041 trsrc.
now = trrepl.
now = 0;
5042 trsrc.
max = trrepl.
max = 0;
5045 for (
i=0;
i<256;
i++) {
5048 while ((c =
trnext(&trsrc, enc)) != errc) {
5057 while ((c =
trnext(&trrepl, enc)) != errc)
5060 for (
i=0;
i<256;
i++) {
5061 if (trans[
i] != errc) {
5069 for (
i=0;
i<256;
i++) {
5072 while ((c =
trnext(&trsrc, enc)) != errc) {
5073 r =
trnext(&trrepl, enc);
5074 if (r == errc) r = trrepl.
now;
5093 unsigned int save = -1;
5109 if (cflag) c =
last;
5112 else if (cflag) c = errc;
5118 if (c != (
unsigned int)-1) {
5130 if (enc != e1) may_modify = 1;
5132 while (t - buf + tlen >= max) {
5139 if (may_modify &&
memcmp(s, t, tlen) != 0) {
5156 c = (
unsigned char)*s;
5157 if (trans[c] != errc) {
5188 if (cflag) c =
last;
5191 else if (cflag) c = errc;
5195 c = cflag ? last : errc;
5203 if (enc != e1) may_modify = 1;
5205 while (t - buf + tlen >= max) {
5213 if (may_modify &&
memcmp(s, t, tlen) != 0) {
5253 return tr_trans(str, src, repl, 0);
5285 #define TR_TABLE_SIZE 257
5290 const unsigned int errc = -1;
5294 VALUE table = 0, ptable = 0;
5295 int i, l, cflag = 0;
5305 for (i=0; i<256; i++) {
5308 stable[256] = cflag;
5310 else if (stable[256] && !cflag) {
5313 for (i=0; i<256; i++) {
5317 while ((c =
trnext(&tr, enc)) != errc) {
5319 buf[c & 0xff] = !cflag;
5340 for (i=0; i<256; i++) {
5341 stable[
i] = stable[
i] && buf[
i];
5350 return table[c] != 0;
5382 VALUE del = 0, nodel = 0;
5384 int i, ascompat, cr;
5390 for (i=0; i<
argc; i++) {
5407 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
5420 if (
tr_find(c, squeez, del, nodel)) {
5435 if (modify)
return str;
5476 VALUE del = 0, nodel = 0;
5486 for (i=0; i<
argc; i++) {
5506 unsigned int c = *(
unsigned char*)s++;
5507 if (c != save || (argc > 0 && !squeez[c])) {
5516 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
5517 if (c != save || (argc > 0 && !squeez[c])) {
5525 if (c != save || (argc > 0 && !
tr_find(c, squeez, del, nodel))) {
5541 if (modify)
return str;
5581 return tr_trans(str, src, repl, 1);
5628 VALUE del = 0, nodel = 0;
5636 for (i=0; i<
argc; i++) {
5650 if (*(
unsigned char*)s++ == c) n++;
5665 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
5674 if (
tr_find(c, table, del, nodel)) {
5685 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
5686 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5687 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5688 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5689 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5690 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5691 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5692 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5693 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5694 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5695 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5696 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5697 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5698 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5699 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5700 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
5703 #define ascii_isspace(c) isspacetable[(unsigned char)(c)]
5753 enum {awk, string, regexp} split_type;
5754 long beg, end,
i = 0;
5758 if (
rb_scan_args(argc, argv,
"02", &spat, &limit) == 2) {
5760 if (lim <= 0) limit =
Qnil;
5761 else if (lim == 1) {
5782 split_type = string;
5786 split_type = regexp;
5803 split_type = regexp;
5809 if (split_type == awk) {
5818 while (ptr < eptr) {
5819 c = (
unsigned char)*ptr++;
5827 if (!
NIL_P(limit) && lim <=
i)
break;
5842 while (ptr < eptr) {
5854 if (!
NIL_P(limit) && lim <= i)
break;
5869 else if (split_type ==
string) {
5883 while (ptr < eptr &&
5884 (end =
rb_memsearch(sptr, slen, ptr, eptr - ptr, enc)) >= 0) {
5887 if (t != ptr + end) {
5893 if (!
NIL_P(limit) && lim <= ++i)
break;
5907 if (start == end &&
BEG(0) ==
END(0)) {
5912 else if (last_null == 1) {
5920 if (ptr+start == ptr+len)
5930 beg = start =
END(0);
5934 for (idx=1; idx < regs->
num_regs; idx++) {
5935 if (
BEG(idx) == -1)
continue;
5936 if (
BEG(idx) ==
END(idx))
5937 tmp = str_new_empty(str);
5942 if (!
NIL_P(limit) && lim <= ++i)
break;
5947 tmp = str_new_empty(str);
5952 if (
NIL_P(limit) && lim == 0) {
6015 unsigned int newline;
6016 const char *
p, *pend, *s, *ptr;
6043 p = memchr(p,
'\n', pend - p);
6074 if (rslen == 0 && c == newline) {
6087 line =
rb_str_new5(str, s, p - s + (rslen ? rslen : n));
6092 s = p + (rslen ? rslen : n);
6174 for (i = 0; i <
len; i += n) {
6180 for (i = 0; i <
len; i += n) {
6215 const char *ptr, *
end;
6236 const char *
p, *p2, *
beg, *
end;
6240 if (beg > end)
return 0;
6323 if (len == 0)
return Qnil;
6375 while (len>0 && p[len-1] ==
'\n') {
6377 if (len>0 && p[len-1] ==
'\r')
6387 if (rslen > len)
return Qnil;
6389 if (rslen == 1 && newline ==
'\n')
6397 if (p[len-1] == newline &&
6530 while (s < t && ((c = *(t-1)) ==
'\0' ||
ascii_isspace(c))) t--;
6637 for (i=1; i < regs->
num_regs; i++) {
6683 long last = -1, prev = 0;
6775 extern char *
crypt(
const char *,
const char *);
6777 const char *s, *saltp;
6780 char salt_8bit_clean[3];
6791 if (!
ISASCII((
unsigned char)saltp[0]) || !
ISASCII((
unsigned char)saltp[1])) {
6792 salt_8bit_clean[0] = saltp[0] & 0x7f;
6793 salt_8bit_clean[1] = saltp[1] & 0x7f;
6794 salt_8bit_clean[2] =
'\0';
6795 saltp = salt_8bit_clean;
6798 res =
crypt(s, saltp);
6873 char *ptr, *
p, *pend;
6876 unsigned long sum0 = 0;
6895 sum0 += (
unsigned char)*p;
6906 if (bits < (
int)
sizeof(
long)*
CHAR_BIT) {
6907 sum0 &= (((
unsigned long)1)<<bits)-1;
6931 long width,
len, flen = 1, fclen = 1;
6934 const char *f =
" ";
6935 long n,
size, llen, rlen, llen2 = 0, rlen2 = 0;
6937 int singlebyte = 1, cr;
6949 if (flen == 0 || fclen == 0) {
6954 if (width < 0 || len >= width)
return rb_str_dup(str);
6956 llen = (jflag ==
'l') ? 0 : ((jflag ==
'r') ? n : n/2);
6960 llen2 =
str_offset(f, f + flen, llen % fclen, enc, singlebyte);
6961 rlen2 =
str_offset(f, f + flen, rlen % fclen, enc, singlebyte);
6964 if ((len = llen / fclen + rlen / fclen) >=
LONG_MAX / flen ||
6965 (len *= flen) >=
LONG_MAX - llen2 - rlen2 ||
6966 (len += llen2 + rlen2) >=
LONG_MAX - size) {
6973 memset(p, *f, llen);
6977 while (llen >= fclen) {
6983 memcpy(p, f, llen2);
6990 memset(p, *f, rlen);
6994 while (rlen >= fclen) {
7000 memcpy(p, f, rlen2);
7114 return rb_ary_new3(3, str, str_new_empty(str), str_new_empty(str));
7118 if (pos == 0 &&
RSTRING_LEN(sep) == 0)
goto failed;
7164 return rb_ary_new3(3, str_new_empty(str), str_new_empty(str), str);
7195 for (i=0; i<
argc; i++) {
7197 if (
NIL_P(tmp))
continue;
7220 for (i=0; i<
argc; i++) {
7222 if (
NIL_P(tmp))
continue;
7316 static const char ellipsis[] =
"...";
7317 const long ellipsislen =
sizeof(ellipsis) - 1;
7320 const char *
const p =
RSTRING_PTR(str), *e = p + blen;
7321 VALUE estr, ret = 0;
7325 (e =
rb_enc_nth(p, e, len, enc)) - p == blen) {
7328 else if (len <= ellipsislen ||
7395 if (sym1 == sym2)
return Qtrue;
7452 memcpy(dest + 1, ptr, len);
7519 enum {SYM_PROC_CACHE_SIZE = 67};
7524 if (!sym_proc_cache) {
7531 index = (
id % SYM_PROC_CACHE_SIZE) << 1;
7534 if (aryp[index] == sym) {
7535 return aryp[index + 1];
7540 aryp[index + 1] = proc;
7716 switch (
TYPE(name)) {
7752 #define rb_intern(str) rb_intern_const(str)