22 #define BEG(no) (regs->beg[(no)])
23 #define END(no) (regs->end[(no)])
32 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
34 #undef rb_str_new_cstr
35 #undef rb_tainted_str_new_cstr
36 #undef rb_usascii_str_new_cstr
37 #undef rb_external_str_new_cstr
38 #undef rb_locale_str_new_cstr
43 #undef rb_tainted_str_new2
44 #undef rb_usascii_str_new2
45 #undef rb_str_dup_frozen
46 #undef rb_str_buf_new_cstr
47 #undef rb_str_buf_new2
48 #undef rb_str_buf_cat2
56 #define RUBY_MAX_CHAR_LEN 16
57 #define STR_TMPLOCK FL_USER7
58 #define STR_NOEMBED FL_USER1
59 #define STR_SHARED FL_USER2
60 #define STR_ASSOC FL_USER3
61 #define STR_SHARED_P(s) FL_ALL((s), STR_NOEMBED|ELTS_SHARED)
62 #define STR_ASSOC_P(s) FL_ALL((s), STR_NOEMBED|STR_ASSOC)
63 #define STR_NOCAPA (STR_NOEMBED|ELTS_SHARED|STR_ASSOC)
64 #define STR_NOCAPA_P(s) (FL_TEST((s),STR_NOEMBED) && FL_ANY((s),ELTS_SHARED|STR_ASSOC))
65 #define STR_UNSET_NOCAPA(s) do {\
66 if (FL_TEST((s),STR_NOEMBED)) FL_UNSET((s),(ELTS_SHARED|STR_ASSOC));\
70 #define STR_SET_NOEMBED(str) do {\
71 FL_SET((str), STR_NOEMBED);\
72 STR_SET_EMBED_LEN((str), 0);\
74 #define STR_SET_EMBED(str) FL_UNSET((str), STR_NOEMBED)
75 #define STR_EMBED_P(str) (!FL_TEST((str), STR_NOEMBED))
76 #define STR_SET_EMBED_LEN(str, n) do { \
78 RBASIC(str)->flags &= ~RSTRING_EMBED_LEN_MASK;\
79 RBASIC(str)->flags |= (tmp_n) << RSTRING_EMBED_LEN_SHIFT;\
82 #define STR_SET_LEN(str, n) do { \
83 if (STR_EMBED_P(str)) {\
84 STR_SET_EMBED_LEN((str), (n));\
87 RSTRING(str)->as.heap.len = (n);\
91 #define STR_DEC_LEN(str) do {\
92 if (STR_EMBED_P(str)) {\
93 long n = RSTRING_LEN(str);\
95 STR_SET_EMBED_LEN((str), n);\
98 RSTRING(str)->as.heap.len--;\
102 #define RESIZE_CAPA(str,capacity) do {\
103 if (STR_EMBED_P(str)) {\
104 if ((capacity) > RSTRING_EMBED_LEN_MAX) {\
105 char *tmp = ALLOC_N(char, (capacity)+1);\
106 memcpy(tmp, RSTRING_PTR(str), RSTRING_LEN(str));\
107 RSTRING(str)->as.heap.ptr = tmp;\
108 RSTRING(str)->as.heap.len = RSTRING_LEN(str);\
109 STR_SET_NOEMBED(str);\
110 RSTRING(str)->as.heap.aux.capa = (capacity);\
114 REALLOC_N(RSTRING(str)->as.heap.ptr, char, (capacity)+1);\
115 if (!STR_NOCAPA_P(str))\
116 RSTRING(str)->as.heap.aux.capa = (capacity);\
120 #define is_ascii_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT)
121 #define is_broken_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN)
123 #define STR_ENC_GET(str) rb_enc_from_index(ENCODING_GET(str))
145 static inline const char *
148 #if SIZEOF_VALUE == 8
149 # define NONASCII_MASK 0x8080808080808080ULL
150 #elif SIZEOF_VALUE == 4
151 # define NONASCII_MASK 0x80808080UL
154 if ((
int)
sizeof(
VALUE) * 2 < e - p) {
157 s = (
const VALUE*)(~lowbits & ((
VALUE)p + lowbits));
158 while (p < (
const char *)s) {
165 if (*s & NONASCII_MASK) {
185 const char *e = p + len;
366 return RSTRING(str)->as.heap.len;
369 return RSTRING(str)->as.heap.aux.capa;
378 str->as.heap.ptr = 0;
379 str->as.heap.len = 0;
380 str->as.heap.aux.capa = 0;
409 RSTRING(str)->as.heap.aux.capa = len;
456 #define rb_str_new2 rb_str_new_cstr
467 #define rb_usascii_str_new2 rb_usascii_str_new_cstr
488 #define rb_tainted_str_new2 rb_tainted_str_new_cstr
499 const unsigned char *start, *sp;
500 unsigned char *dest, *
dp;
501 size_t converted_output = 0;
505 if (from == to)
return str;
520 RBASIC(econv_wrapper)->klass = 0;
527 while ((dest = (
unsigned char*)
RSTRING_PTR(newstr)),
528 (dp = dest + converted_output),
532 size_t converted_input = sp - start;
533 size_t rest = len - converted_input;
534 converted_output = dp - dest;
536 if (converted_input && converted_output &&
537 rest < (
LONG_MAX / converted_output)) {
538 rest = (rest * converted_output) / converted_input;
543 olen += rest < 2 ? 2 : rest;
650 RSTRING(str2)->as.heap.aux.shared = str;
686 #define rb_str_new3 rb_str_new_shared
701 RSTRING(str2)->as.heap.aux.shared = shared;
705 RSTRING(str)->as.heap.aux.shared = str2;
723 if ((ofs > 0) || (klass !=
RBASIC(str)->klass) ||
727 RSTRING(str)->as.heap.ptr += ofs;
728 RSTRING(str)->as.heap.len -= ofs;
741 str = str_new4(klass, orig);
743 RSTRING(str)->as.heap.aux.shared = assoc;
746 str = str_new4(klass, orig);
753 #define rb_str_new4 rb_str_new_frozen
763 #define rb_str_new5 rb_str_new_with_class
766 str_new_empty(
VALUE str)
774 #define STR_BUF_MIN_SIZE 128
785 RSTRING(str)->as.heap.aux.capa = capa;
787 RSTRING(str)->as.heap.ptr[0] =
'\0';
805 #define rb_str_buf_new2 rb_str_buf_new_cstr
841 return RSTRING(str)->as.heap.aux.capa;
861 if (str == str2)
return;
880 RSTRING(str)->as.heap.aux.shared =
RSTRING(str2)->as.heap.aux.shared;
922 RSTRING(str)->as.heap.len = len;
926 RSTRING(str)->as.heap.aux.shared = shared;
973 if (argc > 0 &&
rb_scan_args(argc, argv,
"01", &orig) == 1)
1018 for (c=0; p<e; c++) {
1068 for (c=0; p<e; c++) {
1086 #ifdef NONASCII_MASK
1087 #define is_utf8_lead_byte(c) (((c)&0xC0) != 0x80)
1102 count_utf8_lead_bytes_with_word(
const VALUE *s)
1109 d &= NONASCII_MASK >> 7;
1114 #if SIZEOF_VALUE == 8
1133 #ifdef NONASCII_MASK
1138 if ((
int)
sizeof(
VALUE) * 2 < e - p) {
1141 s = (
const VALUE*)(~lowbits & ((
VALUE)p + lowbits));
1143 while (p < (
const char *)s) {
1144 if (is_utf8_lead_byte(*p)) len++;
1148 len += count_utf8_lead_bytes_with_word(s);
1151 p = (
const char *)s;
1154 if (is_utf8_lead_byte(*p)) len++;
1287 while (n <= len/2) {
1288 memcpy(ptr2 + n, ptr2, n);
1291 memcpy(ptr2 + n, ptr2, len-n);
1351 long capa = len + expand;
1353 if (len > capa) len = capa;
1354 ptr =
ALLOC_N(
char, capa + 1);
1361 RSTRING(str)->as.heap.ptr = ptr;
1362 RSTRING(str)->as.heap.len = len;
1363 RSTRING(str)->as.heap.aux.capa = capa;
1366 #define str_make_independent(str) str_make_independent_expand((str), 0L)
1385 else if (expand > 0) {
1387 long capa = len + expand;
1391 RSTRING(str)->as.heap.aux.capa = capa;
1417 RSTRING(str)->as.heap.ptr = 0;
1418 RSTRING(str)->as.heap.len = 0;
1436 assoc =
RSTRING(assoc)->as.heap.aux.shared;
1458 return RSTRING(str)->as.heap.aux.shared;
1497 if (!s || memchr(s, 0, len)) {
1543 const char *p2, *e2;
1546 while (p < e && 0 < nth) {
1573 while (p < e && nth--) {
1605 const char *pp =
str_nth(p, e, nth, enc, singlebyte);
1606 if (!pp)
return e -
p;
1617 #ifdef NONASCII_MASK
1619 str_utf8_nth(
const char *
p,
const char *e,
long *nthp)
1625 s = (
const VALUE*)(~lowbits & ((
VALUE)p + lowbits));
1627 while (p < (
const char *)s) {
1628 if (is_utf8_lead_byte(*p)) nth--;
1632 nth -= count_utf8_lead_bytes_with_word(s);
1634 }
while (s < t && (
int)
sizeof(
VALUE) <= nth);
1638 if (is_utf8_lead_byte(*p)) {
1639 if (nth == 0)
break;
1649 str_utf8_offset(
const char *p,
const char *e,
long nth)
1651 const char *pp = str_utf8_nth(p, e, &nth);
1698 if (len < 0)
return 0;
1703 if (beg > blen)
return 0;
1706 if (beg < 0)
return 0;
1708 if (beg + len > blen)
1710 if (len < 0)
return 0;
1715 if (len > -beg) len = -beg;
1729 if (beg < 0)
return 0;
1731 if (len == 0)
goto end;
1741 #ifdef NONASCII_MASK
1744 p = str_utf8_nth(s, e, &beg);
1745 if (beg > 0)
return 0;
1746 len = str_utf8_offset(p, e, len);
1752 p = s + beg * char_sz;
1756 else if (len * char_sz > e - p)
1761 else if ((p =
str_nth_len(s, e, &beg, enc)) == e) {
1762 if (beg > 0)
return 0;
1780 if (!p)
return Qnil;
1785 RSTRING(str2)->as.heap.len = len;
1808 #define rb_str_dup_frozen rb_str_new_frozen
1847 rb_bug(
"probable buffer overflow: %ld for %ld", len, capa);
1870 RSTRING(str)->as.ary[len] =
'\0';
1877 char *ptr =
RSTRING(str)->as.heap.ptr;
1879 if (slen > len) slen = len;
1880 if (slen > 0)
MEMCPY(
RSTRING(str)->as.ary, ptr,
char, slen);
1881 RSTRING(str)->as.ary[len] =
'\0';
1883 if (independent)
xfree(ptr);
1886 else if (!independent) {
1889 else if (slen < len || slen - len > 1024) {
1893 RSTRING(str)->as.heap.aux.capa = len;
1895 RSTRING(str)->as.heap.len = len;
1896 RSTRING(str)->as.heap.ptr[len] =
'\0';
1904 long capa, total, off = -1;
1910 if (len == 0)
return 0;
1919 capa =
RSTRING(str)->as.heap.aux.capa;
1925 if (capa <= total) {
1926 while (total > capa) {
1928 capa = (total + 4095) / 4096;
1931 capa = (capa + 1) * 2;
1945 #define str_buf_cat2(str, ptr) str_buf_cat((str), (ptr), strlen(ptr))
1950 if (len == 0)
return str;
1972 p =
RSTRING(str)->as.heap.ptr;
1973 memcpy(p +
RSTRING(str)->as.heap.len, ptr, len);
1974 len =
RSTRING(str)->as.heap.len += len;
1990 int ptr_encindex,
int ptr_cr,
int *ptr_cr_ret)
1998 if (str_encindex == ptr_encindex) {
2028 *ptr_cr_ret = ptr_cr;
2030 if (str_encindex != ptr_encindex &&
2040 res_encindex = str_encindex;
2045 res_encindex = str_encindex;
2049 res_encindex = ptr_encindex;
2054 res_encindex = str_encindex;
2061 res_encindex = str_encindex;
2094 unsigned int c = (
unsigned char)*ptr;
2137 RSTRING(str)->as.heap.len = len;
2185 buf[0] = (char)code;
2281 #define lesser(a,b) (((a)>(b))?(b):(a))
2293 if (idx1 == idx2)
return TRUE;
2312 const char *ptr1, *ptr2;
2315 if (str1 == str2)
return 0;
2318 if (ptr1 == ptr2 || (retval =
memcmp(ptr1, ptr2,
lesser(len1, len2))) == 0) {
2327 if (len1 > len2)
return 1;
2330 if (retval > 0)
return 1;
2339 const char *ptr1, *ptr2;
2345 if (
memcmp(ptr1, ptr2, len) == 0)
2362 if (str1 == str2)
return Qtrue;
2382 if (str1 == str2)
return Qtrue;
2449 char *p1, *p1end, *p2, *p2end;
2460 while (p1 < p1end && p2 < p2end) {
2462 unsigned int c1 =
TOUPPER(*p1 & 0xff);
2463 unsigned int c2 =
TOUPPER(*p2 & 0xff);
2465 return INT2FIX(c1 < c2 ? -1 : 1);
2472 while (p1 < p1end && p2 < p2end) {
2476 if (0 <= c1 && 0 <= c2) {
2480 return INT2FIX(c1 < c2 ? -1 : 1);
2486 len = l1 < l2 ? l1 : l2;
2489 return INT2FIX(r < 0 ? -1 : 1);
2491 return INT2FIX(l1 < l2 ? -1 : 1);
2518 if (offset < 0)
return -1;
2520 if (len - offset < slen)
return -1;
2527 if (slen == 0)
return offset;
2535 if (pos < 0)
return pos;
2537 if (t == s + pos)
break;
2538 if ((len -= t - s) <= 0)
return -1;
2542 return pos + offset;
2570 if (
rb_scan_args(argc, argv,
"11", &sub, &initpos) == 2) {
2616 if (pos == -1)
return Qnil;
2624 char *s, *sbeg, *e, *t;
2635 if (len < slen)
return -1;
2636 if (len - pos < slen) {
2646 s =
str_nth(sbeg, e, pos, enc, singlebyte);
2648 if (
memcmp(s, t, slen) == 0) {
2651 if (pos == 0)
break;
2685 if (
rb_scan_args(argc, argv,
"11", &sub, &vpos) == 2) {
2696 if (pos > len) pos = len;
2713 if (pos >= 0)
return LONG2NUM(pos);
2730 if (pos >= 0)
return LONG2NUM(pos);
2831 for (i = len-1; 0 <= i && (
unsigned char)p[i] == 0xff; i--)
2835 ++((
unsigned char*)p)[
i];
2843 memset(p+l, 0xff, len-l);
2849 for (len2 = len-1; 0 < len2; len2--) {
2854 memset(p+len2+1, 0xff, len-(len2+1));
2865 for (i = len-1; 0 <= i && (
unsigned char)p[i] == 0; i--)
2869 --((
unsigned char*)p)[
i];
2877 memset(p+l, 0, len-l);
2883 for (len2 = len-1; 0 < len2; len2--) {
2888 memset(p+len2+1, 0, len-(len2+1));
2919 MEMCPY(save, p,
char, len);
2926 MEMCPY(p, save,
char, len);
2929 MEMCPY(save, p,
char, len);
2934 MEMCPY(p, save,
char, len);
2939 MEMCPY(p, save,
char, len);
2949 MEMCPY(carry, p,
char, len);
2953 MEMCPY(carry, p,
char, len);
2989 char *sbeg, *s, *e, *last_alnum = 0;
2993 long carry_pos = 0, carry_len = 1;
3025 carry_pos = s - sbeg;
3041 MEMCPY(carry, s,
char, l);
3044 carry_pos = s - sbeg;
3111 VALUE end, exclusive;
3112 VALUE current, after_end;
3119 excl =
RTEST(exclusive);
3129 if (c > e || (excl && c == e))
return beg;
3132 if (!excl && c == e)
break;
3134 if (excl && c == e)
break;
3163 if (excl && bi == ei)
break;
3184 if (n > 0 || (excl && n == 0))
return beg;
3193 if (
NIL_P(next))
break;
3354 if (len > olen) len = olen;
3362 memmove(ptr, oldptr + len, nlen);
3367 ptr =
RSTRING(str)->as.heap.ptr += len;
3368 RSTRING(str)->as.heap.len = nlen;
3433 if (slen < len || slen < beg + len) {
3462 long start, end, len;
3508 switch (
TYPE(indx)) {
3638 for (i=0; i<
argc; i++) {
3643 if (!
NIL_P(result)) {
3655 switch (
TYPE(pat)) {
3725 if (iter || !
NIL_P(hash)) {
3773 memmove(p + beg0 + rlen, p + beg0 + plen, len - beg0 - plen);
3775 memcpy(p + beg0, rp, rlen);
3843 long offset, blen, slen, len,
last;
3869 if (bang)
return Qnil;
3890 if (iter || !
NIL_P(hash)) {
3909 len = beg0 - offset;
3926 offset = end0 + len;
3965 return str_gsub(argc, argv, str, 1);
4015 return str_gsub(argc, argv, str, 0);
4034 if (str == str2)
return str;
4131 if (beg > n || len < 0)
return Qnil;
4134 if (beg < 0)
return Qnil;
4149 RSTRING(str2)->as.heap.len = len;
4183 switch (
TYPE(indx)) {
4279 if (clen > 1 || (*s & 0x80)) single = 0;
4289 if (clen > 1 || (*s & 0x80)) single = 0;
4366 if (i == -1)
return Qfalse;
4397 if (argc == 0) base = 10;
4461 #define CHAR_ESC_LEN 13
4476 else if (c < 0x10000) {
4512 const char *
p, *pend, *prev;
4530 const unsigned char *q = (
const unsigned char *)p;
4531 if (q[0] == 0xFE && q[1] == 0xFF)
4533 else if (q[0] == 0xFF && q[1] == 0xFE)
4538 else if (enc == utf32) {
4539 const unsigned char *q = (
const unsigned char *)p;
4540 if (q[0] == 0 && q[1] == 0 && q[2] == 0xFE && q[3] == 0xFF)
4542 else if (q[3] == 0 && q[2] == 0 && q[1] == 0xFE && q[0] == 0xFF)
4553 if (p > prev)
str_buf_cat(result, prev, p - prev);
4556 n = (int)(pend - p);
4567 if ((asciicompat || unicode_p) &&
4568 (c ==
'"'|| c ==
'\\' ||
4573 (cc ==
'$' || cc ==
'@' || cc ==
'{'))))) {
4574 if (p - n > prev)
str_buf_cat(result, prev, p - n - prev);
4576 if (asciicompat || enc == resenc) {
4582 case '\n': cc =
'n';
break;
4583 case '\r': cc =
'r';
break;
4584 case '\t': cc =
't';
break;
4585 case '\f': cc =
'f';
break;
4586 case '\013': cc =
'v';
break;
4587 case '\010': cc =
'b';
break;
4588 case '\007': cc =
'a';
break;
4589 case 033: cc =
'e';
break;
4590 default: cc = 0;
break;
4593 if (p - n > prev)
str_buf_cat(result, prev, p - n - prev);
4605 if (p - n > prev)
str_buf_cat(result, prev, p - n - prev);
4611 if (p > prev)
str_buf_cat(result, prev, p - prev);
4618 #define IS_EVSTR(p,e) ((p) < (e) && (*(p) == '$' || *(p) == '@' || *(p) == '{'))
4635 const char *
p, *pend;
4643 unsigned char c = *p++;
4645 case '"':
case '\\':
4646 case '\n':
case '\r':
4647 case '\t':
case '\f':
4648 case '\013':
case '\010':
case '\007':
case '\033':
4665 while (cc >>= 4) len++;
4687 unsigned char c = *p++;
4689 if (c ==
'"' || c ==
'\\') {
4693 else if (c ==
'#') {
4694 if (
IS_EVSTR(p, pend)) *q++ =
'\\';
4697 else if (c ==
'\n') {
4701 else if (c ==
'\r') {
4705 else if (c ==
'\t') {
4709 else if (c ==
'\f') {
4713 else if (c ==
'\013') {
4717 else if (c ==
'\010') {
4721 else if (c ==
'\007') {
4725 else if (c ==
'\033') {
4751 snprintf(q, qend-q,
".force_encoding(\"%s\")", enc->
name);
4794 unsigned int c = *(
unsigned char*)s;
4797 *s =
'A' + (c -
'a');
4809 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
4811 *s =
'A' + (c -
'a');
4828 if (modify)
return str;
4876 unsigned int c = *(
unsigned char*)s;
4879 *s =
'a' + (c -
'A');
4892 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
4894 *s =
'a' + (c -
'A');
4911 if (modify)
return str;
4981 if (modify)
return str;
5045 if (modify)
return str;
5086 if (t->
p == t->
pend)
return -1;
5094 if (t->
p < t->
pend) {
5098 if (t->
now < 0x80 && c < 0x80) {
5100 "invalid range \"%c-%c\" in string transliteration",
5137 const unsigned int errc = -1;
5138 unsigned int trans[256];
5140 struct tr trsrc, trrepl;
5142 unsigned int c, c0,
last = 0;
5143 int modify = 0,
i, l;
5149 #define CHECK_IF_ASCII(c) \
5150 (void)((cr == ENC_CODERANGE_7BIT && !rb_isascii(c)) ? \
5151 (cr = ENC_CODERANGE_VALID) : 0)
5172 trsrc.
p + l < trsrc.
pend) {
5178 trsrc.
gen = trrepl.
gen = 0;
5179 trsrc.
now = trrepl.
now = 0;
5180 trsrc.
max = trrepl.
max = 0;
5183 for (
i=0;
i<256;
i++) {
5186 while ((c =
trnext(&trsrc, enc)) != errc) {
5195 while ((c =
trnext(&trrepl, enc)) != errc)
5198 for (
i=0;
i<256;
i++) {
5199 if (trans[
i] != errc) {
5207 for (
i=0;
i<256;
i++) {
5210 while ((c =
trnext(&trsrc, enc)) != errc) {
5211 r =
trnext(&trrepl, enc);
5212 if (r == errc) r = trrepl.
now;
5231 unsigned int save = -1;
5247 if (cflag) c =
last;
5250 else if (cflag) c = errc;
5256 if (c != (
unsigned int)-1) {
5268 if (enc != e1) may_modify = 1;
5270 while (t - buf + tlen >= max) {
5277 if (may_modify &&
memcmp(s, t, tlen) != 0) {
5294 c = (
unsigned char)*s;
5295 if (trans[c] != errc) {
5326 if (cflag) c =
last;
5329 else if (cflag) c = errc;
5333 c = cflag ? last : errc;
5341 if (enc != e1) may_modify = 1;
5343 while (t - buf + tlen >= max) {
5351 if (may_modify &&
memcmp(s, t, tlen) != 0) {
5391 return tr_trans(str, src, repl, 0);
5438 #define TR_TABLE_SIZE 257
5443 const unsigned int errc = -1;
5447 VALUE table = 0, ptable = 0;
5448 int i, l, cflag = 0;
5458 for (i=0; i<256; i++) {
5461 stable[256] = cflag;
5463 else if (stable[256] && !cflag) {
5466 for (i=0; i<256; i++) {
5470 while ((c =
trnext(&tr, enc)) != errc) {
5472 buf[c & 0xff] = !cflag;
5477 if (!table && (first || *tablep || stable[256])) {
5494 for (i=0; i<256; i++) {
5495 stable[
i] = stable[
i] && buf[
i];
5497 if (!table && !cflag) {
5507 return table[
c] != 0;
5539 VALUE del = 0, nodel = 0;
5541 int i, ascompat, cr;
5545 for (i=0; i<
argc; i++) {
5562 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
5575 if (
tr_find(c, squeez, del, nodel)) {
5590 if (modify)
return str;
5631 VALUE del = 0, nodel = 0;
5641 for (i=0; i<
argc; i++) {
5661 unsigned int c = *(
unsigned char*)s++;
5662 if (c != save || (argc > 0 && !squeez[c])) {
5671 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
5672 if (c != save || (argc > 0 && !squeez[c])) {
5680 if (c != save || (argc > 0 && !
tr_find(c, squeez, del, nodel))) {
5696 if (modify)
return str;
5736 return tr_trans(str, src, repl, 1);
5794 VALUE del = 0, nodel = 0;
5800 for (i=0; i<
argc; i++) {
5814 if (*(
unsigned char*)s++ == c) n++;
5829 if (ascompat && (c = *(
unsigned char*)s) < 0x80) {
5838 if (
tr_find(c, table, del, nodel)) {
5849 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
5850 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5851 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5852 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5853 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5854 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5855 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5856 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5857 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5858 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5859 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5860 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5861 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5862 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5863 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5864 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
5867 #define ascii_isspace(c) isspacetable[(unsigned char)(c)]
5922 enum {awk, string, regexp} split_type;
5923 long beg, end,
i = 0;
5927 if (
rb_scan_args(argc, argv,
"02", &spat, &limit) == 2) {
5929 if (lim <= 0) limit =
Qnil;
5930 else if (lim == 1) {
5951 split_type = string;
5955 split_type = regexp;
5972 split_type = regexp;
5978 if (split_type == awk) {
5987 while (ptr < eptr) {
5988 c = (
unsigned char)*ptr++;
5996 if (!
NIL_P(limit) && lim <=
i)
break;
6011 while (ptr < eptr) {
6023 if (!
NIL_P(limit) && lim <= i)
break;
6038 else if (split_type ==
string) {
6052 while (ptr < eptr &&
6053 (end =
rb_memsearch(sptr, slen, ptr, eptr - ptr, enc)) >= 0) {
6056 if (t != ptr + end) {
6062 if (!
NIL_P(limit) && lim <= ++i)
break;
6076 if (start == end &&
BEG(0) ==
END(0)) {
6081 else if (last_null == 1) {
6089 if (ptr+start == ptr+len)
6099 beg = start =
END(0);
6103 for (idx=1; idx < regs->
num_regs; idx++) {
6104 if (
BEG(idx) == -1)
continue;
6105 if (
BEG(idx) ==
END(idx))
6106 tmp = str_new_empty(str);
6111 if (!
NIL_P(limit) && lim <= ++i)
break;
6116 tmp = str_new_empty(str);
6121 if (
NIL_P(limit) && lim == 0) {
6147 unsigned int newline;
6148 const char *
p, *pend, *s, *ptr;
6165 rb_warn(
"given block not used");
6168 rb_warning(
"passing a block to String#lines is deprecated");
6200 p = memchr(p,
'\n', pend - p);
6232 if (rslen == 0 && c == newline) {
6245 const char *pp = p + (rslen ? rslen : n);
6347 rb_warn(
"given block not used");
6350 rb_warning(
"passing a block to String#bytes is deprecated");
6419 const char *end_ptr = ptr + len;
6420 for (len = 0; ptr < end_ptr; ++len) {
6440 rb_warn(
"given block not used");
6443 rb_warning(
"passing a block to String#chars is deprecated");
6462 for (i = 0; i < len; i += n) {
6472 for (i = 0; i < len; i += n) {
6533 const char *ptr, *end;
6543 rb_warn(
"given block not used");
6546 rb_warning(
"passing a block to String#codepoints is deprecated");
6624 const char *
p, *p2, *beg, *end;
6628 if (beg > end)
return 0;
6708 if (len == 0)
return Qnil;
6760 while (len>0 && p[len-1] ==
'\n') {
6762 if (len>0 && p[len-1] ==
'\r')
6772 if (rslen > len)
return Qnil;
6774 if (rslen == 1 && newline ==
'\n')
6782 if (p[len-1] == newline &&
6915 while (s < t && ((c = *(t-1)) ==
'\0' ||
ascii_isspace(c))) t--;
7022 for (i=1; i < regs->
num_regs; i++) {
7068 long last = -1, prev = 0;
7157 extern char *
crypt(
const char *,
const char *);
7159 const char *s, *saltp;
7162 char salt_8bit_clean[3];
7173 if (!
ISASCII((
unsigned char)saltp[0]) || !
ISASCII((
unsigned char)saltp[1])) {
7174 salt_8bit_clean[0] = saltp[0] & 0x7f;
7175 salt_8bit_clean[1] = saltp[1] & 0x7f;
7176 salt_8bit_clean[2] =
'\0';
7177 saltp = salt_8bit_clean;
7180 res =
crypt(s, saltp);
7255 char *ptr, *
p, *pend;
7258 unsigned long sum0 = 0;
7277 sum0 += (
unsigned char)*p;
7288 if (bits < (
int)
sizeof(
long)*
CHAR_BIT) {
7289 sum0 &= (((
unsigned long)1)<<bits)-1;
7313 long width, len, flen = 1, fclen = 1;
7316 const char *
f =
" ";
7317 long n,
size, llen, rlen, llen2 = 0, rlen2 = 0;
7319 int singlebyte = 1, cr;
7331 if (flen == 0 || fclen == 0) {
7336 if (width < 0 || len >= width)
return rb_str_dup(str);
7338 llen = (jflag ==
'l') ? 0 : ((jflag ==
'r') ? n : n/2);
7342 llen2 =
str_offset(f, f + flen, llen % fclen, enc, singlebyte);
7343 rlen2 =
str_offset(f, f + flen, rlen % fclen, enc, singlebyte);
7346 if ((len = llen / fclen + rlen / fclen) >=
LONG_MAX / flen ||
7347 (len *= flen) >=
LONG_MAX - llen2 - rlen2 ||
7348 (len += llen2 + rlen2) >=
LONG_MAX - size) {
7355 memset(p, *f, llen);
7359 while (llen >= fclen) {
7365 memcpy(p, f, llen2);
7372 memset(p, *f, rlen);
7376 while (rlen >= fclen) {
7382 memcpy(p, f, rlen2);
7496 return rb_ary_new3(3, str, str_new_empty(str), str_new_empty(str));
7500 if (pos == 0 &&
RSTRING_LEN(sep) == 0)
goto failed;
7546 return rb_ary_new3(3, str_new_empty(str), str_new_empty(str), str);
7574 for (i=0; i<
argc; i++) {
7599 for (i=0; i<
argc; i++) {
7712 static const char ellipsis[] =
"...";
7713 const long ellipsislen =
sizeof(ellipsis) - 1;
7716 const char *
const p =
RSTRING_PTR(str), *e = p + blen;
7717 VALUE estr, ret = 0;
7721 (e =
rb_enc_nth(p, e, len, enc)) - p == blen) {
7724 else if (len <= ellipsislen ||
7791 if (sym1 == sym2)
return Qtrue;
7889 memcpy(dest + 1, ptr, len);
7956 enum {SYM_PROC_CACHE_SIZE = 67};
7961 if (!sym_proc_cache) {
7968 index = (
id % SYM_PROC_CACHE_SIZE) << 1;
7971 if (aryp[index] == sym) {
7972 return aryp[index + 1];
7977 aryp[index + 1] = proc;
8159 switch (
TYPE(name)) {
8196 #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)
#define rb_usascii_str_new2
int rb_enc_str_asciionly_p(VALUE str)
static VALUE sym_upcase(VALUE sym)
static long chopped_length(VALUE str)
VALUE rb_str_resize(VALUE str, long len)
static VALUE str_replace_shared_without_enc(VALUE str2, VALUE str)
int rb_enc_codelen(int c, rb_encoding *enc)
static VALUE rb_str_bytesize(VALUE str)
#define ONIGERR_TOO_BIG_WIDE_CHAR_VALUE
#define rb_tainted_str_new2
static VALUE str_buf_cat(VALUE str, const char *ptr, long len)
static long rb_str_rindex(VALUE str, VALUE sub, long pos)
rb_encoding * rb_enc_check(VALUE str1, VALUE str2)
VALUE rb_ary_pop(VALUE ary)
#define RESIZE_CAPA(str, capacity)
void rb_bug(const char *fmt,...)
void rb_enc_copy(VALUE obj1, VALUE obj2)
size_t strlen(const char *)
#define CHECK_IF_ASCII(c)
const char * rb_obj_classname(VALUE)
static int sym_printable(const char *s, const char *send, rb_encoding *enc)
VALUE rb_str_equal(VALUE str1, VALUE str2)
#define UNLIMITED_ARGUMENTS
static int max(int a, int b)
VALUE rb_locale_str_new_cstr(const char *ptr)
VALUE rb_sym_to_s(VALUE sym)
static int coderange_scan(const char *p, long len, rb_encoding *enc)
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *eenc)
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.
static VALUE rb_str_to_f(VALUE str)
VALUE rb_str_new_frozen(VALUE orig)
static VALUE rb_str_oct(VALUE str)
st_index_t rb_str_hash(VALUE str)
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *ptr_enc)
static VALUE rb_str_scan(VALUE str, VALUE pat)
VALUE rb_locale_str_new(const char *ptr, long len)
static VALUE rb_str_gsub(int argc, VALUE *argv, VALUE str)
static VALUE rb_str_match(VALUE x, VALUE y)
#define rb_enc_codepoint(p, e, enc)
RUBY_ALIAS_FUNCTION(rb_str_new2(const char *ptr), rb_str_new_cstr,(ptr))
void rb_str_set_len(VALUE str, long len)
static void rb_enc_cr_str_copy_for_substr(VALUE dest, VALUE src)
void rb_gc_force_recycle(VALUE)
static unsigned int trnext(struct tr *t, rb_encoding *enc)
VALUE rb_str_locktmp(VALUE)
#define rb_check_frozen(obj)
#define is_broken_string(str)
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)
static VALUE rb_str_clear(VALUE str)
rb_encoding * rb_to_encoding(VALUE enc)
#define STR_UNSET_NOCAPA(s)
VALUE rb_enc_from_encoding(rb_encoding *encoding)
int rb_enc_tolower(int c, rb_encoding *enc)
VALUE rb_obj_freeze(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)
int rb_usascii_encindex(void)
VALUE rb_str_split(VALUE str, const char *sep0)
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)
VALUE rb_str_export_to_enc(VALUE str, rb_encoding *enc)
static VALUE rb_str_codepoints(VALUE str)
#define str_buf_cat2(str, ptr)
static VALUE rb_str_swapcase_bang(VALUE str)
static VALUE rb_str_rstrip(VALUE str)
VALUE rb_filesystem_str_new(const char *ptr, long len)
VALUE rb_str_export(VALUE str)
static VALUE rb_str_justify(int argc, VALUE *argv, VALUE str, char jflag)
static VALUE rb_str_include(VALUE str, VALUE arg)
static void rb_str_check_dummy_enc(rb_encoding *enc)
#define str_make_independent(str)
VALUE rb_str_freeze(VALUE str)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
long rb_enc_strlen(const char *p, const char *e, rb_encoding *enc)
unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len_p, rb_encoding *enc)
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)
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)
char * rb_string_value_ptr(volatile VALUE *ptr)
static VALUE rb_str_slice_bang(int argc, VALUE *argv, VALUE str)
#define rb_enc_left_char_head(s, p, e, enc)
VALUE rb_str_intern(VALUE s)
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
VALUE rb_ary_new3(long n,...)
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)
static VALUE rb_str_each_char_size(VALUE str)
RUBY_FUNC_EXPORTED size_t rb_str_memsize(VALUE str)
VALUE rb_reg_nth_match(int, VALUE)
static VALUE rb_str_subpat(VALUE str, VALUE re, VALUE backref)
VALUE rb_str_new(const char *ptr, long len)
static VALUE rb_str_aset_m(int argc, VALUE *argv, VALUE str)
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)
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)
VALUE rb_str_export_locale(VALUE str)
static VALUE sym_length(VALUE sym)
VALUE rb_str_new_shared(VALUE str)
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)
static VALUE rb_str_hash_m(VALUE str)
static int tr_find(unsigned int c, char table[TR_TABLE_SIZE], VALUE del, VALUE nodel)
int rb_reg_backref_number(VALUE match, VALUE backref)
#define rb_enc_isctype(c, t, enc)
VALUE rb_equal(VALUE, VALUE)
static VALUE rb_str_aset(VALUE str, VALUE indx, VALUE val)
VALUE rb_enc_sprintf(rb_encoding *enc, const char *format,...)
#define ENCODING_GET(obj)
int rb_enc_toupper(int c, rb_encoding *enc)
static VALUE rb_str_insert(VALUE str, VALUE idx, VALUE str2)
VALUE rb_str_append(VALUE str, VALUE str2)
#define MEMZERO(p, type, n)
static VALUE sym_equal(VALUE sym1, VALUE sym2)
static VALUE sym_inspect(VALUE sym)
int rb_str_hash_cmp(VALUE str1, VALUE str2)
static VALUE rb_str_partition(VALUE str, VALUE sep)
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)
int rb_enc_str_coderange(VALUE str)
VALUE rb_str_plus(VALUE str1, VALUE str2)
static VALUE rb_str_setbyte(VALUE str, VALUE index, VALUE value)
rb_encoding * rb_default_external_encoding(void)
#define ENCODING_CODERANGE_SET(obj, encindex, cr)
static VALUE rb_str_capitalize_bang(VALUE str)
static VALUE rb_str_strip(VALUE str)
#define rb_intern_str(string)
int rb_block_given_p(void)
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)
#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)
static VALUE sym_to_sym(VALUE sym)
void * rb_alloc_tmp_buffer(volatile VALUE *store, long len)
VALUE rb_str_to_inum(VALUE str, int base, int badcheck)
static VALUE str_new_shared(VALUE klass, VALUE str)
VALUE rb_str_length(VALUE str)
static VALUE rb_str_rpartition(VALUE str, VALUE sep)
static VALUE rb_str_crypt(VALUE str, VALUE salt)
static VALUE rb_str_cmp_m(VALUE str1, VALUE str2)
int rb_str_symname_p(VALUE sym)
VALUE rb_str_new_cstr(const char *ptr)
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 ONIGENC_CTYPE_ALPHA
#define ENC_CODERANGE_CLEAR(obj)
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)
static VALUE rb_str_each_byte_size(VALUE str, VALUE args)
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 VALUE rb_str_tr_s_bang(VALUE str, VALUE src, VALUE repl)
#define RUBY_DTRACE_STRING_CREATE_ENABLED()
VALUE rb_str_concat(VALUE str1, VALUE str2)
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)
#define rb_enc_isprint(c, enc)
static VALUE rb_str_strip_bang(VALUE str)
double rb_str_to_dbl(VALUE, int)
VALUE rb_cEncodingConverter
long rb_str_offset(VALUE str, long pos)
#define STR_SET_EMBED_LEN(str, n)
#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
void rb_str_update(VALUE str, long beg, long len, VALUE val)
#define ALLOCA_N(type, n)
VALUE rb_check_funcall(VALUE, ID, int, VALUE *)
static VALUE sym_call(VALUE args, VALUE sym, int argc, VALUE *argv, VALUE passed_proc)
#define ENC_CODERANGE_UNKNOWN
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)
long rb_str_sublen(VALUE str, long pos)
static VALUE sym_capitalize(VALUE sym)
VALUE rb_str_times(VALUE str, VALUE times)
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
static VALUE sym_cmp(VALUE sym, VALUE other)
void rb_str_modify_expand(VALUE str, long expand)
VALUE rb_hash_aset(VALUE, VALUE, VALUE)
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)
static VALUE sym_encoding(VALUE sym)
VALUE rb_str_format(int, const VALUE *, VALUE)
static VALUE rb_str_swapcase(VALUE str)
VALUE rb_obj_as_string(VALUE obj)
#define rb_enc_mbminlen(enc)
VALUE rb_str_subseq(VALUE str, long beg, long len)
char * rb_string_value_cstr(volatile VALUE *ptr)
#define RUBY_MAX_CHAR_LEN
SSL_METHOD *(* func)(void)
static VALUE rb_str_byteslice(int argc, VALUE *argv, VALUE str)
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)
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)
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)
int rb_str_cmp(VALUE str1, VALUE str2)
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_str_buf_new_cstr(const char *ptr)
rb_encoding * rb_usascii_encoding(void)
static VALUE rb_str_aref_m(int argc, VALUE *argv, VALUE str)
static VALUE sym_to_proc(VALUE sym)
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)
VALUE rb_str_buf_cat(VALUE str, const char *ptr, long len)
static enum neighbor_char enc_pred_char(char *p, long len, rb_encoding *enc)
rb_encoding * rb_locale_encoding(void)
VALUE rb_str_replace(VALUE str, VALUE str2)
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)
VALUE rb_str_buf_cat2(VALUE str, const char *ptr)
static VALUE rb_str_is_ascii_only_p(VALUE str)
void rb_str_shared_replace(VALUE str, VALUE str2)
void rb_undef_alloc_func(VALUE)
VALUE rb_obj_encoding(VALUE obj)
#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)
VALUE rb_str_buf_cat_ascii(VALUE str, const char *ptr)
int memcmp(const void *s1, const void *s2, size_t len)
VALUE rb_str_quote_unprintable(VALUE str)
static VALUE sym_casecmp(VALUE sym, VALUE other)
long rb_str_coderange_scan_restartable(const char *s, const char *e, rb_encoding *enc, int *cr)
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)
static const char * search_nonascii(const char *p, const char *e)
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)
VALUE rb_str_to_str(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)
VALUE rb_string_value(volatile VALUE *ptr)
static VALUE rb_str_lines(int argc, VALUE *argv, VALUE str)
VALUE rb_tainted_str_new_cstr(const char *ptr)
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_usascii_str_new(const char *ptr, long len)
VALUE rb_str_buf_append(VALUE str, VALUE str2)
#define ENC_CODERANGE_VALID
static VALUE rb_str_s_try_convert(VALUE dummy, VALUE str)
static VALUE sym_succ(VALUE sym)
void rb_str_free(VALUE str)
VALUE rb_filesystem_str_new_cstr(const char *ptr)
static VALUE rb_str_end_with(int argc, VALUE *argv, VALUE str)
static void str_enc_copy(VALUE str1, VALUE str2)
#define NEWOBJ_OF(obj, type, klass, flags)
#define ENC_CODERANGE_7BIT
rb_encoding * rb_enc_get(VALUE obj)
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
static VALUE rb_str_hex(VALUE str)
char * rb_enc_nth(const char *p, const char *e, long nth, rb_encoding *enc)
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
VALUE rb_str_unlocktmp(VALUE str)
static VALUE rb_str_valid_encoding_p(VALUE str)
static VALUE rb_str_each_byte(VALUE str)
static VALUE rb_str_chop(VALUE str)
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)
static void rb_str_subpat_set(VALUE str, VALUE re, VALUE backref, VALUE val)
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)
static VALUE sym_match(VALUE sym, VALUE other)
VALUE rb_reg_quote(VALUE)
static long rb_str_index(VALUE str, VALUE sub, long offset)
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)
VALUE rb_str_cat(VALUE str, const char *ptr, long len)
long rb_str_strlen(VALUE str)
VALUE rb_str_new_with_class(VALUE, const char *, long)
static VALUE tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p)
#define RARRAY_LENINT(ary)
#define ONIGENC_CTYPE_DIGIT
static VALUE rb_str_capitalize(VALUE str)
VALUE rb_str_drop_bytes(VALUE str, long len)
size_t rb_str_capacity(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)
void rb_str_setter(VALUE val, ID id, VALUE *var)
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)
static VALUE str_replace_shared(VALUE str2, VALUE str)
VALUE rb_backref_get(void)
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
static void str_make_independent_expand(VALUE str, long expand)
VALUE rb_ary_concat(VALUE x, VALUE y)
static unsigned int hash(const char *str, unsigned int len)
static VALUE rb_str_start_with(int argc, VALUE *argv, VALUE str)
VALUE rb_ary_new2(long capa)
VALUE rb_str_substr(VALUE str, long beg, long len)
#define rb_enc_is_newline(p, end, enc)
static void str_discard(VALUE str)
void rb_must_asciicompat(VALUE str)
#define assert(condition)
VALUE rb_range_beg_len(VALUE, long *, long *, long, int)
VALUE rb_str_associated(VALUE str)
#define rb_enc_asciicompat(enc)
VALUE rb_obj_alloc(VALUE)
const char * rb_id2name(ID id)
static VALUE sym_empty(VALUE sym)
static VALUE rb_str_to_s(VALUE str)
#define rb_enc_isupper(c, enc)
#define rb_check_arity(argc, min, max)
static VALUE str_byte_aref(VALUE str, VALUE indx)
VALUE rb_external_str_new(const char *ptr, long len)
void rb_str_associate(VALUE str, VALUE add)
#define rb_enc_isascii(c, enc)
VALUE rb_hash_aref(VALUE, VALUE)
VALUE rb_funcall2(VALUE, ID, int, const VALUE *)
Calls a method.
VALUE rb_str_succ(VALUE orig)
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
#define RSTRING_GETMEM(str, ptrvar, lenvar)
static VALUE rb_str_sum(int argc, VALUE *argv, VALUE str)
VALUE rb_str_inspect(VALUE str)
void rb_free_tmp_buffer(volatile VALUE *store)
static void tr_setup_table(VALUE str, char stable[TR_TABLE_SIZE], int first, VALUE *tablep, VALUE *ctablep, rb_encoding *enc)
#define is_ascii_string(str)
VALUE rb_str_buf_new(long capa)
#define RREGEXP_SRC_LEN(r)
#define SPECIAL_CONST_P(x)
static VALUE rb_str_casecmp(VALUE str1, VALUE str2)
int rb_str_comparable(VALUE str1, VALUE str2)
VALUE rb_str_cat2(VALUE str, const char *ptr)
static char * rb_str_subpos(VALUE str, long beg, long *lenp)
VALUE rb_str_ord(VALUE s)
VALUE rb_str_locktmp_ensure(VALUE str, VALUE(*func)(VALUE), VALUE arg)
#define rb_str_dup_frozen
static VALUE sym_aref(int argc, VALUE *argv, VALUE sym)
VALUE rb_invcmp(VALUE x, VALUE y)
VALUE rb_str_resurrect(VALUE str)
static VALUE rb_str_aref(VALUE str, VALUE indx)
VALUE rb_check_string_type(VALUE str)
#define REALLOC_N(var, type, n)
VALUE rb_id_quote_unprintable(ID id)
VALUE rb_reg_regcomp(VALUE)
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)
#define rb_enc_mbmaxlen(enc)
static VALUE rb_str_delete_bang(int, VALUE *, VALUE)
void rb_warn(const char *fmt,...)
VALUE rb_str_ellipsize(VALUE str, long len)
Shortens str and adds three dots, an ellipsis, if it is longer than len characters.
VALUE rb_convert_type(VALUE, int, const char *, const char *)
static VALUE rb_str_force_encoding(VALUE str, VALUE enc)
rb_encoding * rb_enc_find(const char *name)
VALUE rb_check_convert_type(VALUE, int, const char *, const char *)
VALUE rb_str_dump(VALUE str)
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)
void rb_str_modify(VALUE str)
VALUE rb_enc_str_new(const char *ptr, long len, rb_encoding *enc)
static enum neighbor_char enc_succ_char(char *p, long len, rb_encoding *enc)
VALUE rb_external_str_new_cstr(const char *ptr)
rb_encoding * rb_enc_from_index(int index)
VALUE rb_str_dup(VALUE str)