22 #define BEG(no) (regs->beg[(no)])
23 #define END(no) (regs->end[(no)])
32 #define STRING_ENUMERATORS_WANTARRAY 0
34 #undef rb_str_new_cstr
35 #undef rb_tainted_str_new_cstr
36 #undef rb_usascii_str_new_cstr
37 #undef rb_enc_str_new_cstr
38 #undef rb_external_str_new_cstr
39 #undef rb_locale_str_new_cstr
40 #undef rb_str_dup_frozen
41 #undef rb_str_buf_new_cstr
42 #undef rb_str_buf_cat2
50 #define RUBY_MAX_CHAR_LEN 16
51 #define STR_TMPLOCK FL_USER7
52 #define STR_UNSET_NOCAPA(s) do {\
53 if (FL_TEST((s),STR_NOEMBED)) FL_UNSET((s),(ELTS_SHARED|STR_ASSOC));\
56 #define STR_SET_NOEMBED(str) do {\
57 FL_SET((str), STR_NOEMBED);\
58 STR_SET_EMBED_LEN((str), 0);\
60 #define STR_SET_EMBED(str) FL_UNSET((str), STR_NOEMBED)
61 #define STR_SET_EMBED_LEN(str, n) do { \
63 RBASIC(str)->flags &= ~RSTRING_EMBED_LEN_MASK;\
64 RBASIC(str)->flags |= (tmp_n) << RSTRING_EMBED_LEN_SHIFT;\
67 #define STR_SET_LEN(str, n) do { \
68 if (STR_EMBED_P(str)) {\
69 STR_SET_EMBED_LEN((str), (n));\
72 RSTRING(str)->as.heap.len = (n);\
76 #define STR_DEC_LEN(str) do {\
77 if (STR_EMBED_P(str)) {\
78 long n = RSTRING_LEN(str);\
80 STR_SET_EMBED_LEN((str), n);\
83 RSTRING(str)->as.heap.len--;\
87 #define TERM_LEN(str) rb_enc_mbminlen(rb_enc_get(str))
88 #define TERM_FILL(ptr, termlen) do {\
89 char *const term_fill_ptr = (ptr);\
90 const int term_fill_len = (termlen);\
91 *term_fill_ptr = '\0';\
92 if (UNLIKELY(term_fill_len > 1))\
93 memset(term_fill_ptr, 0, term_fill_len);\
96 #define RESIZE_CAPA(str,capacity) do {\
97 const int termlen = TERM_LEN(str);\
98 if (STR_EMBED_P(str)) {\
99 if ((capacity) > RSTRING_EMBED_LEN_MAX) {\
100 char *const tmp = ALLOC_N(char, (capacity)+termlen);\
101 const long tlen = RSTRING_LEN(str);\
102 memcpy(tmp, RSTRING_PTR(str), tlen);\
103 RSTRING(str)->as.heap.ptr = tmp;\
104 RSTRING(str)->as.heap.len = tlen;\
105 STR_SET_NOEMBED(str);\
106 RSTRING(str)->as.heap.aux.capa = (capacity);\
110 REALLOC_N(RSTRING(str)->as.heap.ptr, char, (capacity)+termlen);\
111 if (!STR_NOCAPA_P(str))\
112 RSTRING(str)->as.heap.aux.capa = (capacity);\
116 #define STR_SET_SHARED(str, shared_str) do { \
117 RB_OBJ_WRITE((str), &RSTRING(str)->as.heap.aux.shared, (shared_str)); \
118 FL_SET((str), ELTS_SHARED); \
121 #define STR_HEAP_PTR(str) (RSTRING(str)->as.heap.ptr)
122 #define STR_HEAP_SIZE(str) (RSTRING(str)->as.heap.aux.capa + TERM_LEN(str))
124 #define STR_ENC_GET(str) get_encoding(str)
131 const unsigned char *
q;
137 if (q[0] == 0xFE && q[1] == 0xFF) {
140 if (q[0] == 0xFF && q[1] == 0xFE) {
147 if (q[0] == 0 && q[1] == 0 && q[2] == 0xFE && q[3] == 0xFF) {
150 if (q[3] == 0 && q[2] == 0 && q[1] == 0xFE && q[0] == 0xFF) {
196 *key = *value = *fstr =
str;
253 static inline const char *
256 #if SIZEOF_VALUE == 8
257 # define NONASCII_MASK 0x8080808080808080ULL
258 #elif SIZEOF_VALUE == 4
259 # define NONASCII_MASK 0x80808080UL
262 if ((
int)
sizeof(
VALUE) * 2 < e - p) {
265 s = (
const VALUE*)(~lowbits & ((
VALUE)p + lowbits));
266 while (p < (
const char *)
s) {
273 if (*s & NONASCII_MASK) {
293 const char *
e = p +
len;
474 return RSTRING(str)->as.heap.len;
477 return RSTRING(str)->as.heap.aux.capa;
530 return str_new0(klass, ptr, len, 1);
615 const unsigned char *start, *sp;
616 unsigned char *dest, *
dp;
617 size_t converted_output = 0;
621 if (from == to)
return str;
644 while ((dest = (
unsigned char*)
RSTRING_PTR(newstr)),
645 (dp = dest + converted_output),
649 size_t converted_input = sp - start;
650 size_t rest = len - converted_input;
651 converted_output = dp - dest;
653 if (converted_input && converted_output &&
654 rest < (
LONG_MAX / converted_output)) {
655 rest = (rest * converted_output) / converted_input;
660 olen += rest < 2 ? 2 : rest;
843 if ((ofs > 0) || (klass !=
RBASIC(str)->klass) ||
847 RSTRING(str)->as.heap.ptr += ofs;
848 RSTRING(str)->as.heap.len -= ofs;
888 #define STR_BUF_MIN_SIZE 128
899 RSTRING(str)->as.heap.aux.capa = capa;
901 RSTRING(str)->as.heap.ptr[0] =
'\0';
976 if (str == str2)
return;
1089 if (argc > 0 &&
rb_scan_args(argc, argv,
"01", &orig) == 1)
1134 for (c=0; p<
e; c++) {
1184 for (c=0; p<
e; c++) {
1202 #ifdef NONASCII_MASK
1203 #define is_utf8_lead_byte(c) (((c)&0xC0) != 0x80)
1218 count_utf8_lead_bytes_with_word(
const VALUE *
s)
1225 d &= NONASCII_MASK >> 7;
1230 #if SIZEOF_VALUE == 8
1249 #ifdef NONASCII_MASK
1254 if ((
int)
sizeof(
VALUE) * 2 < e - p) {
1257 s = (
const VALUE*)(~lowbits & ((
VALUE)p + lowbits));
1259 while (p < (
const char *)
s) {
1260 if (is_utf8_lead_byte(*p)) len++;
1264 len += count_utf8_lead_bytes_with_word(s);
1267 p = (
const char *)s;
1270 if (is_utf8_lead_byte(*p)) len++;
1402 while (n <= len/2) {
1403 memcpy(ptr2 + n, ptr2, n);
1406 memcpy(ptr2 + n, ptr2, len-n);
1465 long capa = len + expand;
1467 if (len > capa) len = capa;
1468 ptr =
ALLOC_N(
char, capa + termlen);
1477 RSTRING(str)->as.heap.aux.capa = capa;
1480 #define str_make_independent(str) str_make_independent_expand((str), 0L)
1499 else if (expand > 0) {
1501 long capa = len + expand;
1506 RSTRING(str)->as.heap.aux.capa = capa;
1532 RSTRING(str)->as.heap.ptr = 0;
1533 RSTRING(str)->as.heap.len = 0;
1551 assoc =
RSTRING(assoc)->as.heap.aux.shared;
1573 return RSTRING(str)->as.heap.aux.shared;
1608 for (; n > 0; --
n) {
1617 const char *
e = s +
len;
1630 if (capa < len + termlen) {
1657 if (!s || memchr(s, 0, len)) {
1712 const char *p2, *e2;
1715 while (p < e && 0 < nth) {
1742 while (p < e && nth--) {
1774 const char *pp =
str_nth(p, e, nth, enc, singlebyte);
1775 if (!pp)
return e -
p;
1786 #ifdef NONASCII_MASK
1788 str_utf8_nth(
const char *
p,
const char *
e,
long *nthp)
1794 s = (
const VALUE*)(~lowbits & ((
VALUE)p + lowbits));
1796 while (p < (
const char *)
s) {
1797 if (is_utf8_lead_byte(*p)) nth--;
1801 nth -= count_utf8_lead_bytes_with_word(s);
1803 }
while (s < t && (
int)
sizeof(
VALUE) <= nth);
1807 if (is_utf8_lead_byte(*p)) {
1808 if (nth == 0)
break;
1818 str_utf8_offset(
const char *p,
const char *e,
long nth)
1820 const char *pp = str_utf8_nth(p, e, &nth);
1867 if (len < 0)
return 0;
1872 if (beg > blen)
return 0;
1875 if (beg < 0)
return 0;
1877 if (beg + len > blen)
1879 if (len < 0)
return 0;
1884 if (len > -beg) len = -beg;
1898 if (beg < 0)
return 0;
1900 if (len == 0)
goto end;
1910 #ifdef NONASCII_MASK
1913 p = str_utf8_nth(s, e, &beg);
1914 if (beg > 0)
return 0;
1915 len = str_utf8_offset(p, e, len);
1921 p = s + beg * char_sz;
1925 else if (len * char_sz > e - p)
1930 else if ((p =
str_nth_len(s, e, &beg, enc)) == e) {
1931 if (beg > 0)
return 0;
1949 if (!p)
return Qnil;
1977 #define rb_str_dup_frozen rb_str_new_frozen
2017 rb_bug(
"probable buffer overflow: %ld for %ld", len, capa);
2040 if (len == slen)
return str;
2052 if (slen > len) slen =
len;
2053 if (slen > 0)
MEMCPY(
RSTRING(str)->as.ary, ptr,
char, slen);
2059 else if (!independent) {
2060 if (len == slen)
return str;
2063 else if ((capa =
RSTRING(str)->as.heap.aux.capa) < len ||
2064 (capa - len) > (len < 1024 ? len : 1024)) {
2068 else if (len == slen)
return str;
2078 long capa, total, off = -1;
2085 if (len == 0)
return 0;
2094 capa =
RSTRING(str)->as.heap.aux.capa;
2100 if (capa <= total) {
2101 while (total > capa) {
2102 if (capa + termlen >=
LONG_MAX / 2) {
2103 capa = (total + 4095) / 4096 * 4096;
2106 capa = (capa + termlen) * 2;
2120 #define str_buf_cat2(str, ptr) str_buf_cat((str), (ptr), strlen(ptr))
2125 if (len == 0)
return str;
2147 p =
RSTRING(str)->as.heap.ptr;
2165 int ptr_encindex,
int ptr_cr,
int *ptr_cr_ret)
2173 if (str_encindex == ptr_encindex) {
2203 *ptr_cr_ret = ptr_cr;
2205 if (str_encindex != ptr_encindex &&
2215 res_encindex = str_encindex;
2220 res_encindex = str_encindex;
2224 res_encindex = ptr_encindex;
2229 res_encindex = str_encindex;
2236 res_encindex = str_encindex;
2269 unsigned int c = (
unsigned char)*ptr;
2305 long len1 =
RSTRING(str)->as.heap.len,
len = len1 + len2;
2361 buf[0] = (char)code;
2457 #define lesser(a,b) (((a)>(b))?(b):(a))
2469 if (idx1 == idx2)
return TRUE;
2488 const char *ptr1, *ptr2;
2491 if (str1 == str2)
return 0;
2494 if (ptr1 == ptr2 || (retval =
memcmp(ptr1, ptr2,
lesser(len1, len2))) == 0) {
2503 if (len1 > len2)
return 1;
2506 if (retval > 0)
return 1;
2515 const char *ptr1, *ptr2;
2521 if (
memcmp(ptr1, ptr2, len) == 0)
2544 if (str1 == str2)
return Qtrue;
2564 if (str1 == str2)
return Qtrue;
2631 char *p1, *p1end, *p2, *p2end;
2642 while (p1 < p1end && p2 < p2end) {
2644 unsigned int c1 =
TOUPPER(*p1 & 0xff);
2645 unsigned int c2 =
TOUPPER(*p2 & 0xff);
2647 return INT2FIX(c1 < c2 ? -1 : 1);
2654 while (p1 < p1end && p2 < p2end) {
2658 if (0 <= c1 && 0 <= c2) {
2662 return INT2FIX(c1 < c2 ? -1 : 1);
2668 len = l1 < l2 ? l1 : l2;
2671 return INT2FIX(r < 0 ? -1 : 1);
2673 return INT2FIX(l1 < l2 ? -1 : 1);
2688 long pos,
len, slen;
2699 if (offset < 0)
return -1;
2701 if (len - offset < slen)
return -1;
2706 offset =
str_offset(s, e, offset, enc, single_byte);
2709 if (slen == 0)
return offset;
2717 if (pos < 0)
return pos;
2719 if (t == s + pos)
break;
2721 if (len <= 0)
return -1;
2725 return pos + offset;
2753 if (
rb_scan_args(argc, argv,
"11", &sub, &initpos) == 2) {
2799 if (pos == -1)
return Qnil;
2807 char *hit, *adjusted;
2809 long slen, searchlen;
2813 if (slen == 0)
return pos;
2818 searchlen = s - sbeg + 1;
2821 hit = memrchr(sbeg, c, searchlen);
2824 if (hit != adjusted) {
2825 searchlen = adjusted - sbeg;
2828 if (
memcmp(hit, t, slen) == 0)
2830 searchlen = adjusted - sbeg;
2831 }
while (searchlen > 0);
2848 if (
memcmp(s, t, slen) == 0) {
2851 if (pos == 0)
break;
2875 if (len < slen)
return -1;
2876 if (len - pos < slen) pos = len - slen;
2877 if (len == 0)
return pos;
2919 if (
rb_scan_args(argc, argv,
"11", &sub, &vpos) == 2) {
2930 if (pos > len) pos =
len;
2947 if (pos >= 0)
return LONG2NUM(pos);
2964 if (pos >= 0)
return LONG2NUM(pos);
3083 for (i = len-1; 0 <= i && (
unsigned char)p[i] == 0xff; i--)
3087 ++((
unsigned char*)p)[
i];
3095 memset(p+l, 0xff, len-l);
3101 for (len2 = len-1; 0 < len2; len2--) {
3106 memset(p+len2+1, 0xff, len-(len2+1));
3136 for (i = len-1; 0 <= i && (
unsigned char)p[i] == 0; i--)
3140 --((
unsigned char*)p)[
i];
3154 for (len2 = len-1; 0 < len2; len2--) {
3159 memset(p+len2+1, 0, len-(len2+1));
3184 const int max_gaps = 1;
3194 MEMCPY(save, p,
char, len);
3195 for (
try = 0;
try <= max_gaps; ++
try) {
3203 MEMCPY(p, save,
char, len);
3206 MEMCPY(save, p,
char, len);
3211 MEMCPY(p, save,
char, len);
3216 MEMCPY(p, save,
char, len);
3226 MEMCPY(carry, p,
char, len);
3230 MEMCPY(carry, p,
char, len);
3266 char *sbeg, *
s, *
e, *last_alnum = 0;
3270 long carry_pos = 0, carry_len = 1;
3304 carry_pos = s - sbeg;
3333 MEMCPY(carry, s,
char, l);
3336 carry_pos = s - sbeg;
3411 excl =
RTEST(exclusive);
3421 if (c > e || (excl && c == e))
return beg;
3424 if (!excl && c == e)
break;
3426 if (excl && c == e)
break;
3455 if (excl && bi == ei)
break;
3476 if (n > 0 || (excl && n == 0))
return beg;
3485 if (
NIL_P(next))
break;
3646 if (len > olen) len = olen;
3654 memmove(ptr, oldptr + len, nlen);
3660 RSTRING(str)->as.heap.len = nlen;
3725 if (slen < len || slen < beg + len) {
3800 switch (
TYPE(indx)) {
3930 for (i=0; i<
argc; i++) {
3935 if (!
NIL_P(result)) {
3947 switch (
TYPE(pat)) {
4015 if (iter || !
NIL_P(hash)) {
4062 memmove(p + beg0 + rlen, p + beg0 + plen, len - beg0 - plen);
4064 memcpy(p + beg0, rp, rlen);
4134 long offset, blen, slen,
len,
last;
4160 if (bang)
return Qnil;
4181 if (iter || !
NIL_P(hash)) {
4200 len = beg0 - offset;
4217 offset = end0 +
len;
4256 return str_gsub(argc, argv, str, 1);
4306 return str_gsub(argc, argv, str, 0);
4325 if (str == str2)
return str;
4422 if (beg > n || len < 0)
return Qnil;
4425 if (beg < 0)
return Qnil;
4474 switch (
TYPE(indx)) {
4652 if (i == -1)
return Qfalse;
4683 if (argc == 0) base = 10;
4747 #define CHAR_ESC_LEN 13
4762 else if (c < 0x10000) {
4799 const char *
p, *pend, *prev;
4814 if (actenc != enc) {
4824 if (p > prev)
str_buf_cat(result, prev, p - prev);
4827 n = (
int)(pend - p);
4838 if ((asciicompat || unicode_p) &&
4839 (c ==
'"'|| c ==
'\\' ||
4844 (cc ==
'$' || cc ==
'@' || cc ==
'{'))))) {
4845 if (p - n > prev)
str_buf_cat(result, prev, p - n - prev);
4847 if (asciicompat || enc == resenc) {
4853 case '\n': cc =
'n';
break;
4854 case '\r': cc =
'r';
break;
4855 case '\t': cc =
't';
break;
4856 case '\f': cc =
'f';
break;
4857 case '\013': cc =
'v';
break;
4858 case '\010': cc =
'b';
break;
4859 case '\007': cc =
'a';
break;
4860 case 033: cc =
'e';
break;
4861 default: cc = 0;
break;
4864 if (p - n > prev)
str_buf_cat(result, prev, p - n - prev);
4876 if (p - n > prev)
str_buf_cat(result, prev, p - n - prev);
4882 if (p > prev)
str_buf_cat(result, prev, p - prev);
4889 #define IS_EVSTR(p,e) ((p) < (e) && (*(p) == '$' || *(p) == '@' || *(p) == '{'))
4906 const char *
p, *pend;
4914 unsigned char c = *p++;
4916 case '"':
case '\\':
4917 case '\n':
case '\r':
4918 case '\t':
case '\f':
4919 case '\013':
case '\010':
case '\007':
case '\033':
4932 if (u8 && c > 0x7F) {
4936 while (cc >>= 4) len++;
4958 unsigned char c = *p++;
4960 if (c ==
'"' || c ==
'\\') {
4964 else if (c ==
'#') {
4965 if (
IS_EVSTR(p, pend)) *q++ =
'\\';
4968 else if (c ==
'\n') {
4972 else if (c ==
'\r') {
4976 else if (c ==
'\t') {
4980 else if (c ==
'\f') {
4984 else if (c ==
'\013') {
4988 else if (c ==
'\010') {
4992 else if (c ==
'\007') {
4996 else if (c ==
'\033') {
5022 snprintf(q, qend-q,
".force_encoding(\"%s\")", enc->
name);
5065 unsigned int c = *(
unsigned char*)s;
5068 *s =
'A' + (c -
'a');
5080 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
5082 *s =
'A' + (c -
'a');
5099 if (modify)
return str;
5147 unsigned int c = *(
unsigned char*)s;
5150 *s =
'a' + (c -
'A');
5163 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
5165 *s =
'a' + (c -
'A');
5182 if (modify)
return str;
5252 if (modify)
return str;
5316 if (modify)
return str;
5357 if (t->
p == t->
pend)
return -1;
5365 if (t->
p < t->
pend) {
5369 if (t->
now < 0x80 && c < 0x80) {
5371 "invalid range \"%c-%c\" in string transliteration",
5408 const unsigned int errc = -1;
5409 unsigned int trans[256];
5411 struct tr trsrc, trrepl;
5413 unsigned int c, c0,
last = 0;
5414 int modify = 0,
i, l;
5420 #define CHECK_IF_ASCII(c) \
5421 (void)((cr == ENC_CODERANGE_7BIT && !rb_isascii(c)) ? \
5422 (cr = ENC_CODERANGE_VALID) : 0)
5443 trsrc.
p + l < trsrc.
pend) {
5449 trsrc.
gen = trrepl.
gen = 0;
5450 trsrc.
now = trrepl.
now = 0;
5451 trsrc.
max = trrepl.
max = 0;
5454 for (
i=0;
i<256;
i++) {
5457 while ((c =
trnext(&trsrc, enc)) != errc) {
5466 while ((c =
trnext(&trrepl, enc)) != errc)
5469 for (
i=0;
i<256;
i++) {
5470 if (trans[
i] != errc) {
5478 for (
i=0;
i<256;
i++) {
5481 while ((c =
trnext(&trsrc, enc)) != errc) {
5482 r =
trnext(&trrepl, enc);
5483 if (r == errc) r = trrepl.
now;
5502 unsigned int save = -1;
5518 if (cflag) c =
last;
5521 else if (cflag) c = errc;
5527 if (c != (
unsigned int)-1) {
5539 if (enc != e1) may_modify = 1;
5541 while (t - buf + tlen >= max) {
5548 if (may_modify &&
memcmp(s, t, tlen) != 0) {
5565 c = (
unsigned char)*s;
5566 if (trans[c] != errc) {
5597 if (cflag) c =
last;
5600 else if (cflag) c = errc;
5604 c = cflag ? last : errc;
5612 if (enc != e1) may_modify = 1;
5614 while (t - buf + tlen >= max) {
5622 if (may_modify &&
memcmp(s, t, tlen) != 0) {
5662 return tr_trans(str, src, repl, 0);
5709 #define TR_TABLE_SIZE 257
5714 const unsigned int errc = -1;
5719 int i, l, cflag = 0;
5729 for (i=0; i<256; i++) {
5732 stable[256] = cflag;
5734 else if (stable[256] && !cflag) {
5737 for (i=0; i<256; i++) {
5741 while ((c =
trnext(&tr, enc)) != errc) {
5743 buf[c & 0xff] = !cflag;
5748 if (!table && (first || *tablep || stable[256])) {
5765 for (i=0; i<256; i++) {
5766 stable[
i] = stable[
i] && buf[
i];
5768 if (!table && !cflag) {
5810 VALUE del = 0, nodel = 0;
5812 int i, ascompat, cr;
5816 for (i=0; i<
argc; i++) {
5833 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
5846 if (
tr_find(c, squeez, del, nodel)) {
5861 if (modify)
return str;
5902 VALUE del = 0, nodel = 0;
5912 for (i=0; i<
argc; i++) {
5932 unsigned int c = *(
unsigned char*)s++;
5933 if (c != save || (argc > 0 && !squeez[c])) {
5942 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
5943 if (c != save || (argc > 0 && !squeez[c])) {
5951 if (c != save || (argc > 0 && !
tr_find(c, squeez, del, nodel))) {
5967 if (modify)
return str;
6007 return tr_trans(str, src, repl, 1);
6065 VALUE del = 0, nodel = 0, tstr;
6089 if (*(
unsigned char*)s++ == c) n++;
6096 for (i=1; i<
argc; i++) {
6111 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
6120 if (
tr_find(c, table, del, nodel)) {
6131 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
6132 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6133 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6134 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6135 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6136 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6137 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6138 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6139 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6140 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6141 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
6149 #define ascii_isspace(c) isspacetable[(unsigned char)(c)]
6204 enum {awk, string, regexp} split_type;
6205 long beg,
end,
i = 0;
6209 if (
rb_scan_args(argc, argv,
"02", &spat, &limit) == 2) {
6211 if (lim <= 0) limit =
Qnil;
6212 else if (lim == 1) {
6228 split_type = string;
6232 split_type = regexp;
6249 split_type = regexp;
6255 if (split_type == awk) {
6264 while (ptr < eptr) {
6265 c = (
unsigned char)*ptr++;
6273 if (!
NIL_P(limit) && lim <=
i)
break;
6288 while (ptr < eptr) {
6300 if (!
NIL_P(limit) && lim <= i)
break;
6315 else if (split_type ==
string) {
6329 while (ptr < eptr &&
6330 (end =
rb_memsearch(sptr, slen, ptr, eptr - ptr, enc)) >= 0) {
6333 if (t != ptr + end) {
6339 if (!
NIL_P(limit) && lim <= ++i)
break;
6353 if (start == end &&
BEG(0) ==
END(0)) {
6358 else if (last_null == 1) {
6366 if (ptr+start == ptr+len)
6376 beg = start =
END(0);
6380 for (idx=1; idx < regs->
num_regs; idx++) {
6381 if (
BEG(idx) == -1)
continue;
6382 if (
BEG(idx) ==
END(idx))
6388 if (!
NIL_P(limit) && lim <= ++i)
break;
6398 if (
NIL_P(limit) && lim == 0) {
6424 const char *
ptr, *pend, *subptr, *subend, *rsptr, *hit, *adjusted;
6425 long pos,
len, rslen;
6426 int paragraph_mode = 0;
6437 #if STRING_ENUMERATORS_WANTARRAY
6438 rb_warn(
"given block not used");
6441 rb_warning(
"passing a block to String#lines is deprecated");
6492 while (subptr < pend) {
6493 pos =
rb_memsearch(rsptr, rslen, subptr, pend - subptr, enc);
6497 if (hit != adjusted) {
6501 subend = hit + rslen;
6502 if (paragraph_mode) {
6518 if (subptr != pend) {
6606 #if STRING_ENUMERATORS_WANTARRAY
6607 rb_warn(
"given block not used");
6610 rb_warning(
"passing a block to String#bytes is deprecated");
6695 #if STRING_ENUMERATORS_WANTARRAY
6696 rb_warn(
"given block not used");
6699 rb_warning(
"passing a block to String#chars is deprecated");
6714 for (i = 0; i <
len; i +=
n) {
6724 for (i = 0; i <
len; i +=
n) {
6799 #if STRING_ENUMERATORS_WANTARRAY
6800 rb_warn(
"given block not used");
6803 rb_warning(
"passing a block to String#codepoints is deprecated");
6877 const char *
p, *p2, *beg, *
end;
6881 if (beg > end)
return 0;
6961 if (len == 0)
return Qnil;
7013 while (len>0 && p[len-1] ==
'\n') {
7015 if (len>0 && p[len-1] ==
'\r')
7025 if (rslen > len)
return Qnil;
7027 if (rslen == 1 && newline ==
'\n')
7035 if (p[len-1] == newline &&
7171 while (s < t && ((c = *(t-1)) ==
'\0' ||
ascii_isspace(c))) t--;
7278 for (i=1; i < regs->
num_regs; i++) {
7324 long last = -1, prev = 0;
7413 extern char *
crypt(
const char *,
const char *);
7415 const char *
s, *saltp;
7418 char salt_8bit_clean[3];
7429 if (!
ISASCII((
unsigned char)saltp[0]) || !
ISASCII((
unsigned char)saltp[1])) {
7430 salt_8bit_clean[0] = saltp[0] & 0x7f;
7431 salt_8bit_clean[1] = saltp[1] & 0x7f;
7432 salt_8bit_clean[2] =
'\0';
7433 saltp = salt_8bit_clean;
7436 res =
crypt(s, saltp);
7510 char *
ptr, *
p, *pend;
7513 unsigned long sum0 = 0;
7532 sum0 += (
unsigned char)*p;
7543 if (bits < (
int)
sizeof(
long)*
CHAR_BIT) {
7544 sum0 &= (((
unsigned long)1)<<bits)-1;
7568 long width,
len, flen = 1, fclen = 1;
7571 const char *
f =
" ";
7572 long n,
size, llen, rlen, llen2 = 0, rlen2 = 0;
7574 int singlebyte = 1, cr;
7586 if (flen == 0 || fclen == 0) {
7591 if (width < 0 || len >= width)
return rb_str_dup(str);
7593 llen = (jflag ==
'l') ? 0 : ((jflag ==
'r') ? n : n/2);
7597 llen2 =
str_offset(f, f + flen, llen % fclen, enc, singlebyte);
7598 rlen2 =
str_offset(f, f + flen, rlen % fclen, enc, singlebyte);
7601 if ((len = llen / fclen + rlen / fclen) >=
LONG_MAX / flen ||
7602 (len *= flen) >=
LONG_MAX - llen2 - rlen2 ||
7603 (len += llen2 + rlen2) >=
LONG_MAX - size) {
7614 while (llen >= fclen) {
7631 while (rlen >= fclen) {
7755 if (pos == 0 &&
RSTRING_LEN(sep) == 0)
goto failed;
7833 for (i=0; i<
argc; i++) {
7858 for (i=0; i<
argc; i++) {
7971 static const char ellipsis[] =
"...";
7972 const long ellipsislen =
sizeof(ellipsis) - 1;
7975 const char *
const p =
RSTRING_PTR(str), *e = p + blen;
7980 (e =
rb_enc_nth(p, e, len, enc)) - p == blen) {
7983 else if (len <= ellipsislen ||
8061 #define DEFAULT_REPLACE_CHAR(str) do { \
8062 static const char replace[sizeof(str)-1] = str; \
8063 rep = replace; replen = (int)sizeof(replace); \
8076 else if (!
NIL_P(repl)) {
8115 if (e - p < clen) clen = e -
p;
8122 for (; clen > 1; clen--) {
8218 if (e - p < clen) clen = e -
p;
8219 if (clen <= mbminlen * 2) {
8224 for (; clen > mbminlen; clen-=mbminlen) {
8365 if (sym1 == sym2)
return Qtrue;
8463 memcpy(dest + 1, ptr, len);
8530 enum {SYM_PROC_CACHE_SIZE = 67};
8535 if (!sym_proc_cache) {
8542 index = (
id % SYM_PROC_CACHE_SIZE) << 1;
8545 if (aryp[index] == sym) {
8546 return aryp[index + 1];
8552 aryp[index + 1] =
proc;
8769 #define rb_intern(str) rb_intern_const(str)
static int str_independent(VALUE str)
#define rb_enc_islower(c, enc)
#define RB_TYPE_P(obj, type)
static VALUE sym_upcase(VALUE sym)
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
static VALUE str_new4(VALUE klass, VALUE str)
static long chopped_length(VALUE str)
VALUE rb_str_associated(VALUE)
static VALUE str_replace_shared_without_enc(VALUE str2, VALUE str)
int rb_enc_codelen(int c, rb_encoding *enc)
VALUE rb_str_locktmp_ensure(VALUE str, VALUE(*func)(VALUE), VALUE arg)
static VALUE rb_str_bytesize(VALUE str)
#define ONIGERR_TOO_BIG_WIDE_CHAR_VALUE
static VALUE str_buf_cat(VALUE str, const char *ptr, long len)
VALUE rb_str_times(VALUE, VALUE)
static long rb_str_rindex(VALUE str, VALUE sub, long pos)
rb_encoding * rb_enc_check(VALUE str1, VALUE str2)
VALUE rb_str_ellipsize(VALUE, long)
Shortens str and adds three dots, an ellipsis, if it is longer than len characters.
VALUE rb_ary_pop(VALUE ary)
rb_funcall2(argv[0], id_yield, argc-1, argv+1)
#define RESIZE_CAPA(str, capacity)
void rb_bug(const char *fmt,...)
VALUE rb_ary_new_capa(long capa)
#define RB_OBJ_WRITE(a, slot, b)
void rb_enc_copy(VALUE obj1, VALUE obj2)
VALUE rb_str_resurrect(VALUE str)
size_t strlen(const char *)
#define CHECK_IF_ASCII(c)
const char * rb_obj_classname(VALUE)
VALUE rb_str_buf_cat_ascii(VALUE, const char *)
static int sym_printable(const char *s, const char *send, rb_encoding *enc)
#define UNLIMITED_ARGUMENTS
static rb_encoding * get_actual_encoding(const int encidx, VALUE str)
static int max(int a, int b)
static int coderange_scan(const char *p, long len, rb_encoding *enc)
VALUE rb_str_tmp_new(long)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
VALUE rb_str_buf_append(VALUE, VALUE)
static VALUE rb_str_to_f(VALUE str)
static VALUE rb_str_oct(VALUE str)
static VALUE str_compat_and_valid(VALUE str, rb_encoding *enc)
VALUE rb_string_value(volatile VALUE *)
VALUE rb_str_quote_unprintable(VALUE)
static VALUE rb_str_scan(VALUE str, VALUE pat)
static VALUE rb_str_gsub(int argc, VALUE *argv, VALUE str)
static VALUE rb_str_match(VALUE x, VALUE y)
rb_funcall(memo->yielder, id_lshift, 1, rb_assoc_new(memo->prev_value, memo->prev_elts))
SSL_METHOD *(* func)(void)
VALUE rb_block_clear_env_self(VALUE proc)
#define rb_enc_codepoint(p, e, enc)
int rb_str_cmp(VALUE, VALUE)
static void rb_enc_cr_str_copy_for_substr(VALUE dest, VALUE src)
VALUE rb_external_str_new_cstr(const char *)
void rb_gc_force_recycle(VALUE)
char * rb_string_value_ptr(volatile VALUE *)
static unsigned int trnext(struct tr *t, rb_encoding *enc)
VALUE rb_str_locktmp(VALUE)
#define rb_check_frozen(obj)
RUBY_EXTERN void * memmove(void *, const void *, size_t)
#define rb_enc_right_char_head(s, p, e, enc)
static VALUE sym_swapcase(VALUE sym)
static VALUE rb_str_b(VALUE str)
VALUE rb_str_subseq(VALUE, long, long)
static VALUE rb_str_clear(VALUE str)
rb_encoding * rb_to_encoding(VALUE enc)
VALUE rb_str_new_cstr(const char *)
#define STR_UNSET_NOCAPA(s)
VALUE rb_enc_from_encoding(rb_encoding *encoding)
int rb_enc_tolower(int c, rb_encoding *enc)
RUBY_EXTERN VALUE rb_cSymbol
VALUE rb_obj_freeze(VALUE)
long rb_str_strlen(VALUE)
int rb_num_to_uint(VALUE val, unsigned int *ret)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
static VALUE str_gsub(int argc, VALUE *argv, VALUE str, int bang)
static VALUE rb_str_succ_bang(VALUE str)
static VALUE rb_str_enumerate_bytes(VALUE str, int wantarray)
static VALUE rb_str_each_line(int argc, VALUE *argv, VALUE str)
#define rb_enc_prev_char(s, p, e, enc)
rb_encoding * rb_default_internal_encoding(void)
VALUE rb_ary_push(VALUE ary, VALUE item)
static VALUE str_new3(VALUE klass, VALUE str)
VALUE rb_reg_regsub(VALUE, VALUE, struct re_registers *, VALUE)
VALUE rb_str_export(VALUE)
static VALUE rb_str_each_byte_size(VALUE str, VALUE args, VALUE eobj)
static VALUE rb_str_prepend(VALUE str, VALUE str2)
rb_encoding * rb_enc_compatible(VALUE str1, VALUE str2)
static VALUE rb_str_gsub_bang(int argc, VALUE *argv, VALUE str)
VALUE rb_ary_tmp_new(long capa)
static int fstr_update_callback(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
static VALUE rb_str_codepoints(VALUE str)
#define str_buf_cat2(str, ptr)
static VALUE rb_str_swapcase_bang(VALUE str)
int rb_str_comparable(VALUE, VALUE)
VALUE rb_str_buf_cat2(VALUE, const char *)
static VALUE rb_str_rstrip(VALUE str)
static VALUE rb_str_justify(int argc, VALUE *argv, VALUE str, char jflag)
#define RGENGC_WB_PROTECTED_STRING
static VALUE rb_str_include(VALUE str, VALUE arg)
static void rb_str_check_dummy_enc(rb_encoding *enc)
#define str_make_independent(str)
#define MBCLEN_NEEDMORE_P(ret)
unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len_p, rb_encoding *enc)
static VALUE str_new0(VALUE klass, const char *ptr, long len, int termlen)
long rb_enc_strlen_cr(const char *p, const char *e, rb_encoding *enc, int *cr)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_funcall_with_block(VALUE, ID, int, const VALUE *, VALUE)
char * rb_enc_nth(const char *, const char *, long, rb_encoding *)
static VALUE sym_downcase(VALUE sym)
VALUE rb_proc_new(VALUE(*)(ANYARGS), VALUE)
static VALUE str_replace(VALUE str, VALUE str2)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
VALUE rb_obj_class(VALUE)
#define RETURN_ENUMERATOR(obj, argc, argv)
static VALUE rb_str_to_i(int argc, VALUE *argv, VALUE str)
static VALUE rb_str_slice_bang(int argc, VALUE *argv, VALUE str)
#define rb_enc_left_char_head(s, p, e, enc)
VALUE rb_external_str_new(const char *, long)
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
static rb_encoding * get_encoding(VALUE str)
static VALUE rb_str_empty(VALUE str)
static VALUE rb_str_chars(VALUE str)
static VALUE rb_str_reverse_bang(VALUE str)
void rb_include_module(VALUE klass, VALUE module)
#define rb_enc_to_index(enc)
static VALUE rb_str_center(int argc, VALUE *argv, VALUE str)
VALUE rb_locale_str_new(const char *, long)
#define DEFAULT_REPLACE_CHAR(str)
VALUE rb_reg_nth_match(int, VALUE)
static VALUE rb_str_subpat(VALUE str, VALUE re, VALUE backref)
void rb_must_asciicompat(VALUE)
static VALUE rb_str_aset_m(int argc, VALUE *argv, VALUE str)
static const char * str_null_char(const char *s, long len, const int minlen, rb_encoding *enc)
VALUE rb_str_unlocktmp(VALUE)
static char * str_fill_term(VALUE str, char *s, long len, int oldtermlen, int termlen)
static VALUE rb_str_upcase_bang(VALUE str)
static VALUE rb_str_format_m(VALUE str, VALUE arg)
#define STR_SET_NOEMBED(str)
#define ENCODING_IS_ASCII8BIT(obj)
VALUE rb_str_substr(VALUE, long, long)
static long str_strlen(VALUE str, rb_encoding *enc)
static VALUE rb_str_chomp(int argc, VALUE *argv, VALUE str)
rb_encoding * rb_utf8_encoding(void)
static VALUE sym_length(VALUE sym)
void rb_undef_method(VALUE klass, const char *name)
#define ENC_CODERANGE_BROKEN
VALUE rb_sym_all_symbols(void)
static VALUE empty_str_alloc(VALUE klass)
static VALUE rb_str_upcase(VALUE str)
VALUE rb_str_new_frozen(VALUE)
static VALUE rb_str_hash_m(VALUE str)
static int fstring_cmp(VALUE a, VALUE b)
int rb_reg_backref_number(VALUE match, VALUE backref)
#define rb_enc_isctype(c, t, enc)
VALUE rb_equal(VALUE, VALUE)
VALUE rb_str_concat(VALUE, VALUE)
static VALUE rb_str_aset(VALUE str, VALUE indx, VALUE val)
VALUE rb_str_replace(VALUE, VALUE)
#define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc, s, end)
VALUE rb_str_to_str(VALUE)
void rb_str_modify_expand(VALUE, long)
VALUE rb_enc_sprintf(rb_encoding *enc, const char *format,...)
VALUE rb_str_equal(VALUE str1, VALUE str2)
#define ENCODING_GET(obj)
int rb_enc_toupper(int c, rb_encoding *enc)
static VALUE rb_str_insert(VALUE str, VALUE idx, VALUE str2)
#define MEMZERO(p, type, n)
static VALUE sym_equal(VALUE sym1, VALUE sym2)
static VALUE sym_inspect(VALUE sym)
int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg)
static VALUE rb_str_partition(VALUE str, VALUE sep)
VALUE rb_usascii_str_new(const char *, long)
int st_delete(st_table *, st_data_t *, st_data_t *)
static long str_offset(const char *p, const char *e, long nth, rb_encoding *enc, int singlebyte)
static VALUE rb_str_ljust(int argc, VALUE *argv, VALUE str)
static int fstring_set_class_i(st_data_t key, st_data_t val, st_data_t arg)
void rb_str_update(VALUE, long, long, VALUE)
static VALUE rb_str_setbyte(VALUE str, VALUE index, VALUE value)
rb_encoding * rb_default_external_encoding(void)
memset(y->frac+ix+1, 0,(y->Prec-(ix+1))*sizeof(BDIGIT))
static st_table * frozen_strings
VALUE rb_external_str_with_enc(VALUE str, rb_encoding *eenc)
#define ONIGENC_MBCLEN_CHARFOUND_LEN(r)
#define ENCODING_CODERANGE_SET(obj, encindex, cr)
static VALUE rb_str_capitalize_bang(VALUE str)
int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p)
static VALUE rb_str_strip(VALUE str)
#define rb_intern_str(string)
int rb_block_given_p(void)
long rb_str_offset(VALUE, long)
rb_econv_result_t rb_econv_convert(rb_econv_t *ec, const unsigned char **source_buffer_ptr, const unsigned char *source_buffer_end, unsigned char **destination_buffer_ptr, unsigned char *destination_buffer_end, int flags)
size_t rb_str_capacity(VALUE)
#define rb_enc_step_back(s, p, e, n, enc)
static VALUE rb_str_split_m(int argc, VALUE *argv, VALUE str)
static int single_byte_optimizable(VALUE str)
int rb_enc_fast_mbclen(const char *p, const char *e, rb_encoding *enc)
static void rb_str_splice_0(VALUE str, long beg, long len, VALUE val)
void rb_free_tmp_buffer(volatile VALUE *store)
static VALUE sym_to_sym(VALUE sym)
VALUE rb_str_to_inum(VALUE str, int base, int badcheck)
static VALUE str_new_shared(VALUE klass, VALUE str)
int rb_str_symname_p(VALUE)
static VALUE rb_str_rpartition(VALUE str, VALUE sep)
static VALUE rb_str_crypt(VALUE str, VALUE salt)
VALUE rb_locale_str_new_cstr(const char *)
static VALUE rb_str_cmp_m(VALUE str1, VALUE str2)
#define RARRAY_CONST_PTR(a)
#define RARRAY_AREF(a, i)
static void str_modify_keep_cr(VALUE str)
#define STR_SET_EMBED(str)
static VALUE rb_str_tr_s(VALUE str, VALUE src, VALUE repl)
#define rb_usascii_encindex()
#define ONIGENC_CTYPE_ALPHA
#define ENC_CODERANGE_CLEAR(obj)
VALUE rb_str_cat2(VALUE, const char *)
static VALUE rb_str_delete(int argc, VALUE *argv, VALUE str)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rb_enc_set_index(VALUE obj, int idx)
void rb_str_shared_replace(VALUE, VALUE)
static VALUE rb_str_enumerate_chars(VALUE str, int wantarray)
static VALUE rb_str_enumerate_lines(int argc, VALUE *argv, VALUE str, int wantarray)
void rb_ary_store(VALUE ary, long idx, VALUE val)
static struct st_hash_type fstring_hash_type
static VALUE rb_str_tr_s_bang(VALUE str, VALUE src, VALUE repl)
#define RUBY_DTRACE_STRING_CREATE_ENABLED()
void rb_backref_set(VALUE)
static int rb_enc_dummy_p(rb_encoding *enc)
#define MBCLEN_CHARFOUND_P(ret)
#define ENC_CODERANGE_AND(a, b)
RUBY_ALIAS_FUNCTION(rb_str_dup_frozen(VALUE str), rb_str_new_frozen,(str))
#define rb_enc_isprint(c, enc)
static VALUE rb_str_strip_bang(VALUE str)
double rb_str_to_dbl(VALUE, int)
VALUE rb_cEncodingConverter
#define STR_SET_EMBED_LEN(str, n)
VALUE rb_str_freeze(VALUE)
#define range(low, item, hi)
VALUE rb_check_hash_type(VALUE)
static VALUE rb_str_tr_bang(VALUE str, VALUE src, VALUE repl)
#define RUBY_FUNC_EXPORTED
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_str_buf_new_cstr(const char *)
static VALUE rb_str_each_char_size(VALUE str, VALUE args, VALUE eobj)
#define ALLOCA_N(type, n)
static VALUE sym_call(VALUE args, VALUE sym, int argc, VALUE *argv, VALUE passed_proc)
#define ENC_CODERANGE_UNKNOWN
void rb_str_setter(VALUE, ID, VALUE *)
static VALUE rb_str_rjust(int argc, VALUE *argv, VALUE str)
#define rb_enc_mbc_to_codepoint(p, e, enc)
#define ENC_CODERANGE_SET(obj, cr)
VALUE rb_reg_match(VALUE, VALUE)
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts)
VALUE rb_str_new_shared(VALUE)
static VALUE sym_capitalize(VALUE sym)
VALUE rb_str_buf_cat(VALUE, const char *, long)
VALUE rb_tainted_str_new_cstr(const char *)
#define rb_utf8_encindex()
VALUE rb_filesystem_str_new(const char *, long)
VALUE rb_obj_as_string(VALUE)
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
static VALUE sym_cmp(VALUE sym, VALUE other)
static void rb_str_splice(VALUE str, long beg, long len, VALUE val)
VALUE rb_tainted_str_new(const char *, long)
static VALUE str_eql(const VALUE str1, const VALUE str2)
VALUE rb_str_resize(VALUE, long)
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
static VALUE sym_encoding(VALUE sym)
VALUE rb_str_format(int, const VALUE *, VALUE)
static VALUE rb_str_swapcase(VALUE str)
VALUE rb_str_export_to_enc(VALUE, rb_encoding *)
VALUE rb_str_scrub(VALUE, VALUE)
#define rb_enc_mbminlen(enc)
#define RUBY_MAX_CHAR_LEN
static VALUE rb_str_byteslice(int argc, VALUE *argv, VALUE str)
static long str_rindex(VALUE str, VALUE sub, const char *s, long pos, rb_encoding *enc)
VALUE rb_str_split(VALUE, const char *)
void rb_econv_close(rb_econv_t *ec)
#define rb_enc_mbcput(c, buf, enc)
long rb_memsearch(const void *, long, const void *, long, rb_encoding *)
#define MBCLEN_CHARFOUND_LEN(ret)
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
int rb_enc_unicode_p(rb_encoding *enc)
long rb_str_coderange_scan_restartable(const char *, const char *, rb_encoding *, int *)
int rb_enc_symname_p(const char *name, rb_encoding *enc)
static VALUE rb_str_tr(VALUE str, VALUE src, VALUE repl)
#define CONST_ID(var, str)
static VALUE rb_str_chop_bang(VALUE str)
void rb_gc_register_mark_object(VALUE)
static VALUE str_new_empty(VALUE str)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static VALUE rb_str_enumerate_codepoints(VALUE str, int wantarray)
static VALUE rb_str_squeeze(int argc, VALUE *argv, VALUE str)
long rb_reg_search(VALUE, VALUE, long, int)
static VALUE str_duplicate(VALUE klass, VALUE str)
char * rb_string_value_cstr(volatile VALUE *)
rb_encoding * rb_usascii_encoding(void)
static VALUE rb_str_aref_m(int argc, VALUE *argv, VALUE str)
void rb_gc_resurrect(VALUE ptr)
static VALUE str_scrub_bang(int argc, VALUE *argv, VALUE str)
static VALUE sym_to_proc(VALUE sym)
VALUE rb_str_inspect(VALUE)
static VALUE rb_str_squeeze_bang(int argc, VALUE *argv, VALUE str)
RUBY_EXTERN char * crypt(const char *, const char *)
static VALUE get_pat(VALUE, int)
static enum neighbor_char enc_pred_char(char *p, long len, rb_encoding *enc)
static int tr_find(unsigned int c, const char table[TR_TABLE_SIZE], VALUE del, VALUE nodel)
VALUE rb_str_buf_new(long)
rb_encoding * rb_locale_encoding(void)
static VALUE rb_str_lstrip_bang(VALUE str)
static VALUE str_new(VALUE klass, const char *ptr, long len)
static VALUE str_alloc(VALUE klass)
#define UNINITIALIZED_VAR(x)
static VALUE rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
static VALUE rb_str_is_ascii_only_p(VALUE str)
rb_hash_aset(hash, RARRAY_AREF(key_value_pair, 0), RARRAY_AREF(key_value_pair, 1))
void rb_undef_alloc_func(VALUE)
VALUE rb_obj_encoding(VALUE obj)
void void ruby_sized_xfree(void *x, size_t size)
#define TERM_FILL(ptr, termlen)
#define RUBY_DTRACE_STRING_CREATE(arg0, arg1, arg2)
rb_econv_t * rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts)
static VALUE rb_str_chomp_bang(int argc, VALUE *argv, VALUE str)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
int memcmp(const void *s1, const void *s2, size_t len)
static VALUE sym_casecmp(VALUE sym, VALUE other)
static int zero_filled(const char *s, int n)
static char * str_nth_len(const char *p, const char *e, long *nthp, rb_encoding *enc)
static VALUE rb_str_getbyte(VALUE str, VALUE index)
static void rb_enc_cr_str_exact_copy(VALUE dest, VALUE src)
void rb_sys_fail(const char *mesg)
static VALUE rb_str_chr(VALUE str)
RUBY_EXTERN VALUE rb_cString
static const char * search_nonascii(const char *p, const char *e)
VALUE rb_id_quote_unprintable(ID)
static VALUE str_scrub(int argc, VALUE *argv, VALUE str)
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts)
static void str_modifiable(VALUE str)
static VALUE rb_str_bytes(VALUE str)
static VALUE rb_str_index_m(int argc, VALUE *argv, VALUE str)
static VALUE rb_str_match_m(int argc, VALUE *argv, VALUE str)
#define RSTRING_EMBED_LEN_MAX
static void str_mod_check(VALUE s, const char *p, long len)
static VALUE rb_str_lines(int argc, VALUE *argv, VALUE str)
static const char isspacetable[256]
#define MEMCPY(p1, p2, type, n)
static VALUE scan_once(VALUE str, VALUE pat, long *start)
static VALUE rb_str_sub(int argc, VALUE *argv, VALUE str)
VALUE rb_str_export_locale(VALUE)
#define ENC_CODERANGE_VALID
static VALUE rb_str_s_try_convert(VALUE dummy, VALUE str)
static VALUE sym_succ(VALUE sym)
static VALUE rb_str_end_with(int argc, VALUE *argv, VALUE str)
static void str_enc_copy(VALUE str1, VALUE str2)
void rb_str_modify(VALUE)
#define NEWOBJ_OF(obj, type, klass, flags)
void * rb_alloc_tmp_buffer(volatile VALUE *store, long len) RUBY_ATTR_ALLOC_SIZE((2))
VALUE rb_str_cat(VALUE, const char *, long)
VALUE rb_str_length(VALUE)
#define ENC_CODERANGE_7BIT
rb_encoding * rb_enc_get(VALUE obj)
#define STR_SET_SHARED(str, shared_str)
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
#define STR_HEAP_PTR(str)
#define OBJ_TAINTED_RAW(x)
static VALUE rb_str_hex(VALUE str)
static char * str_nth(const char *p, const char *e, long nth, rb_encoding *enc, int singlebyte)
static VALUE rb_str_reverse(VALUE str)
static VALUE rb_str_downcase(VALUE str)
#define ONIGENC_CODE_TO_MBCLEN(enc, code)
RUBY_EXTERN VALUE rb_default_rs
static VALUE rb_str_valid_encoding_p(VALUE str)
static VALUE rb_str_each_byte(VALUE str)
static VALUE rb_str_chop(VALUE str)
long rb_str_sublen(VALUE, long)
static VALUE rb_str_count(int argc, VALUE *argv, VALUE str)
#define STR_SET_LEN(str, n)
static VALUE rb_str_eql(VALUE str1, VALUE str2)
int rb_enc_str_asciionly_p(VALUE)
static void rb_str_subpat_set(VALUE str, VALUE re, VALUE backref, VALUE val)
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *)
void rb_str_associate(VALUE, VALUE)
static long enc_strlen(const char *p, const char *e, rb_encoding *enc, int cr)
static VALUE rb_str_lstrip(VALUE str)
#define MBCLEN_INVALID_P(ret)
st_index_t rb_memhash(const void *ptr, long len)
#define ENC_CODERANGE(obj)
VALUE rb_check_array_type(VALUE ary)
static enum neighbor_char enc_succ_alnum_char(char *p, long len, rb_encoding *enc, char *carry)
#define rb_str_dup_frozen
static VALUE sym_match(VALUE sym, VALUE other)
VALUE rb_reg_quote(VALUE)
void rb_str_fill_terminator(VALUE str, const int termlen)
static long rb_str_index(VALUE str, VALUE sub, long offset)
st_index_t rb_str_hash(VALUE)
RUBY_EXTERN VALUE rb_cObject
static VALUE rb_str_upto(int argc, VALUE *argv, VALUE beg)
static VALUE str_byte_substr(VALUE str, long beg, long len)
#define rb_enc_code_to_mbclen(c, enc)
VALUE rb_str_new_with_class(VALUE, const char *, long)
static VALUE tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
#define RARRAY_LENINT(ary)
#define ONIGENC_CTYPE_DIGIT
static VALUE rb_str_capitalize(VALUE str)
void rb_define_variable(const char *, VALUE *)
rb_encoding * rb_filesystem_encoding(void)
static VALUE rb_str_init(int argc, VALUE *argv, VALUE str)
rb_encoding * rb_enc_get_from_index(int index)
int rb_respond_to(VALUE, ID)
#define ONIGENC_CODE_TO_MBC_MAXLEN
static VALUE rb_str_rstrip_bang(VALUE str)
static VALUE rb_str_each_char(VALUE str)
#define RBASIC_SET_CLASS(obj, cls)
static VALUE str_replace_shared(VALUE str2, VALUE str)
VALUE rb_backref_get(void)
static void str_make_independent_expand(VALUE str, long expand)
VALUE rb_ary_concat(VALUE x, VALUE y)
VALUE rb_enc_str_new_cstr(const char *, rb_encoding *)
static VALUE rb_str_start_with(int argc, VALUE *argv, VALUE str)
VALUE rb_str_new(const char *, long)
#define rb_enc_is_newline(p, end, enc)
VALUE rb_str_drop_bytes(VALUE, long)
static void str_discard(VALUE str)
#define assert(condition)
VALUE rb_range_beg_len(VALUE, long *, long *, long, int)
#define rb_enc_asciicompat(enc)
VALUE rb_obj_alloc(VALUE)
const char * rb_id2name(ID id)
st_table * st_init_table(const struct st_hash_type *)
VALUE rb_str_intern(VALUE)
static VALUE sym_empty(VALUE sym)
static VALUE rb_str_to_s(VALUE str)
#define rb_enc_isupper(c, enc)
static VALUE str_byte_aref(VALUE str, VALUE indx)
#define RBASIC_CLEAR_CLASS(obj)
#define rb_enc_isascii(c, enc)
int rb_str_hash_cmp(VALUE, VALUE)
VALUE rb_hash_aref(VALUE, VALUE)
rb_encoding * rb_ascii8bit_encoding(void)
static VALUE rb_str_downcase_bang(VALUE str)
static VALUE rb_enc_cr_str_buf_cat(VALUE str, const char *ptr, long len, int ptr_encindex, int ptr_cr, int *ptr_cr_ret)
void rb_warning(const char *fmt,...)
#define ONIGERR_INVALID_CODE_POINT_VALUE
char * rb_str_subpos(VALUE, long, long *)
#define RSTRING_GETMEM(str, ptrvar, lenvar)
static VALUE rb_str_sum(int argc, VALUE *argv, VALUE str)
static void tr_setup_table(VALUE str, char stable[TR_TABLE_SIZE], int first, VALUE *tablep, VALUE *ctablep, rb_encoding *enc)
#define RREGEXP_SRC_LEN(r)
#define SPECIAL_CONST_P(x)
static VALUE rb_str_casecmp(VALUE str1, VALUE str2)
#define OBJ_INFECT_RAW(x, s)
VALUE rb_filesystem_str_new_cstr(const char *)
VALUE rb_str_ord(VALUE s)
static VALUE sym_aref(int argc, VALUE *argv, VALUE sym)
VALUE rb_invcmp(VALUE x, VALUE y)
static VALUE rb_str_aref(VALUE str, VALUE indx)
VALUE rb_check_string_type(VALUE)
#define REALLOC_N(var, type, n)
VALUE rb_reg_regcomp(VALUE)
int rb_enc_str_coderange(VALUE)
long rb_enc_strlen(const char *, const char *, rb_encoding *)
static int match(VALUE str, VALUE pat, VALUE hash, int(*cb)(VALUE, VALUE))
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
#define rb_enc_mbmaxlen(enc)
static VALUE rb_str_delete_bang(int, VALUE *, VALUE)
size_t rb_str_memsize(VALUE)
void rb_warn(const char *fmt,...)
#define is_broken_string(str)
VALUE rb_convert_type(VALUE, int, const char *, const char *)
static VALUE rb_str_force_encoding(VALUE str, VALUE enc)
#define STR_HEAP_SIZE(str)
VALUE rb_check_convert_type(VALUE, int, const char *, const char *)
static VALUE rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
VALUE rb_usascii_str_new_cstr(const char *)
static VALUE rb_str_each_codepoint(VALUE str)
STATIC void unsigned char * cp
VALUE rb_str_plus(VALUE, VALUE)
#define is_ascii_string(str)
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc)
static enum neighbor_char enc_succ_char(char *p, long len, rb_encoding *enc)
rb_encoding * rb_enc_from_index(int index)
#define ONIGENC_MBCLEN_CHARFOUND_P(r)
void rb_str_set_len(VALUE, long)