23#define errcpy(err, msg) strlcpy((err), (msg), ONIG_MAX_ERROR_MESSAGE_LEN)
25#define BEG(no) (regs->beg[(no)])
26#define END(no) (regs->end[(no)])
29static const char casetable[] = {
30 '\000',
'\001',
'\002',
'\003',
'\004',
'\005',
'\006',
'\007',
31 '\010',
'\011',
'\012',
'\013',
'\014',
'\015',
'\016',
'\017',
32 '\020',
'\021',
'\022',
'\023',
'\024',
'\025',
'\026',
'\027',
33 '\030',
'\031',
'\032',
'\033',
'\034',
'\035',
'\036',
'\037',
35 '\040',
'\041',
'\042',
'\043',
'\044',
'\045',
'\046',
'\047',
37 '\050',
'\051',
'\052',
'\053',
'\054',
'\055',
'\056',
'\057',
39 '\060',
'\061',
'\062',
'\063',
'\064',
'\065',
'\066',
'\067',
41 '\070',
'\071',
'\072',
'\073',
'\074',
'\075',
'\076',
'\077',
43 '\100',
'\141',
'\142',
'\143',
'\144',
'\145',
'\146',
'\147',
45 '\150',
'\151',
'\152',
'\153',
'\154',
'\155',
'\156',
'\157',
47 '\160',
'\161',
'\162',
'\163',
'\164',
'\165',
'\166',
'\167',
49 '\170',
'\171',
'\172',
'\133',
'\134',
'\135',
'\136',
'\137',
51 '\140',
'\141',
'\142',
'\143',
'\144',
'\145',
'\146',
'\147',
53 '\150',
'\151',
'\152',
'\153',
'\154',
'\155',
'\156',
'\157',
55 '\160',
'\161',
'\162',
'\163',
'\164',
'\165',
'\166',
'\167',
57 '\170',
'\171',
'\172',
'\173',
'\174',
'\175',
'\176',
'\177',
58 '\200',
'\201',
'\202',
'\203',
'\204',
'\205',
'\206',
'\207',
59 '\210',
'\211',
'\212',
'\213',
'\214',
'\215',
'\216',
'\217',
60 '\220',
'\221',
'\222',
'\223',
'\224',
'\225',
'\226',
'\227',
61 '\230',
'\231',
'\232',
'\233',
'\234',
'\235',
'\236',
'\237',
62 '\240',
'\241',
'\242',
'\243',
'\244',
'\245',
'\246',
'\247',
63 '\250',
'\251',
'\252',
'\253',
'\254',
'\255',
'\256',
'\257',
64 '\260',
'\261',
'\262',
'\263',
'\264',
'\265',
'\266',
'\267',
65 '\270',
'\271',
'\272',
'\273',
'\274',
'\275',
'\276',
'\277',
66 '\300',
'\301',
'\302',
'\303',
'\304',
'\305',
'\306',
'\307',
67 '\310',
'\311',
'\312',
'\313',
'\314',
'\315',
'\316',
'\317',
68 '\320',
'\321',
'\322',
'\323',
'\324',
'\325',
'\326',
'\327',
69 '\330',
'\331',
'\332',
'\333',
'\334',
'\335',
'\336',
'\337',
70 '\340',
'\341',
'\342',
'\343',
'\344',
'\345',
'\346',
'\347',
71 '\350',
'\351',
'\352',
'\353',
'\354',
'\355',
'\356',
'\357',
72 '\360',
'\361',
'\362',
'\363',
'\364',
'\365',
'\366',
'\367',
73 '\370',
'\371',
'\372',
'\373',
'\374',
'\375',
'\376',
'\377',
76# error >>> "You lose. You will need a translation table for your character set." <<<
82 const unsigned char *p1 = x, *p2 = y;
86 if ((tmp = casetable[(
unsigned)*p1++] - casetable[(
unsigned)*p2++]))
94rb_memsearch_ss(
const unsigned char *xs,
long m,
const unsigned char *ys,
long n)
96 const unsigned char *y;
105rb_memsearch_ss(
const unsigned char *xs,
long m,
const unsigned char *ys,
long n)
107 const unsigned char *x = xs, *xe = xs + m;
108 const unsigned char *y = ys, *ye = ys +
n;
109#define VALUE_MAX ((VALUE)~(VALUE)0)
113 rb_bug(
"!!too long pattern string!!");
115 if (!(y =
memchr(y, *x,
n - m + 1)))
119 for (hx = *x++, hy = *y++; x < xe; ++x, ++y) {
139rb_memsearch_qs(
const unsigned char *xs,
long m,
const unsigned char *ys,
long n)
141 const unsigned char *x = xs, *xe = xs + m;
142 const unsigned char *y = ys;
146 for (
i = 0;
i < 256; ++
i)
149 qstable[*x] = xe - x;
151 for (; y + m <= ys +
n; y += *(qstable + y[m])) {
152 if (*xs == *y &&
memcmp(xs, y, m) == 0)
158static inline unsigned int
159rb_memsearch_qs_utf8_hash(
const unsigned char *x)
161 register const unsigned int mix = 8353;
162 register unsigned int h = *x;
187 return (
unsigned char)
h;
191rb_memsearch_qs_utf8(
const unsigned char *xs,
long m,
const unsigned char *ys,
long n)
193 const unsigned char *x = xs, *xe = xs + m;
194 const unsigned char *y = ys;
198 for (
i = 0;
i < 512; ++
i) {
201 for (; x < xe; ++x) {
202 qstable[rb_memsearch_qs_utf8_hash(x)] = xe - x;
205 for (; y + m <= ys +
n; y += qstable[rb_memsearch_qs_utf8_hash(y+m)]) {
206 if (*xs == *y &&
memcmp(xs, y, m) == 0)
213rb_memsearch_wchar(
const unsigned char *xs,
long m,
const unsigned char *ys,
long n)
215 const unsigned char *x = xs, x0 = *xs, *y = ys;
219 if (x0 == *y &&
memcmp(x+1, y+1, m-1) == 0)
226rb_memsearch_qchar(
const unsigned char *xs,
long m,
const unsigned char *ys,
long n)
228 const unsigned char *x = xs, x0 = *xs, *y = ys;
232 if (x0 == *y &&
memcmp(x+1, y+1, m-1) == 0)
241 const unsigned char *x = x0, *y =
y0;
243 if (m >
n)
return -1;
245 return memcmp(x0,
y0, m) == 0 ? 0 : -1;
251 const unsigned char *ys =
memchr(y, *x,
n);
260 return rb_memsearch_ss(x0, m,
y0,
n);
263 return rb_memsearch_qs_utf8(x0, m,
y0,
n);
267 return rb_memsearch_wchar(x0, m,
y0,
n);
270 return rb_memsearch_qchar(x0, m,
y0,
n);
272 return rb_memsearch_qs(x0, m,
y0,
n);
275#define REG_LITERAL FL_USER5
276#define REG_ENCODING_NONE FL_USER6
278#define KCODE_FIXED FL_USER4
280#define ARG_REG_OPTION_MASK \
281 (ONIG_OPTION_IGNORECASE|ONIG_OPTION_MULTILINE|ONIG_OPTION_EXTEND)
282#define ARG_ENCODING_FIXED 16
283#define ARG_ENCODING_NONE 32
308option_to_str(
char str[4],
int options)
338 return (*option = char_to_option(c));
345rb_reg_check(
VALUE re)
356 const char *p, *pend;
361 p = s; pend = p +
len;
368 p +=
mbclen(p, pend, enc);
396 if (c ==
'\\' && p+clen < pend) {
397 int n = clen +
mbclen(p+clen, pend, enc);
405 c = (
unsigned char)*p;
418 else if (c ==
term) {
430 snprintf(b,
sizeof(b),
"\\x%02X", c);
442rb_reg_desc(
const char *s,
long len,
VALUE re)
455 rb_reg_expr_str(
str, s,
len, enc, resenc,
'/');
460 if (*option_to_str(opts,
RREGEXP_PTR(re)->options))
484rb_reg_source(
VALUE re)
506rb_reg_inspect(
VALUE re)
539 return rb_reg_str_with_term(re,
'/');
560 if (
len >= 4 &&
ptr[0] ==
'(' &&
ptr[1] ==
'?') {
563 if ((
len -= 2) > 0) {
565 opt = char_to_option((
int )*
ptr);
575 if (
len > 1 && *
ptr ==
'-') {
579 opt = char_to_option((
int )*
ptr);
615 if ((options & embeddable) != embeddable) {
617 option_to_str(optbuf + 1, ~options);
654rb_reg_raise(
const char *s,
long len,
const char *
err,
VALUE re)
656 VALUE desc = rb_reg_desc(s,
len, re);
662rb_enc_reg_error_desc(
const char *s,
long len,
rb_encoding *enc,
int options,
const char *
err)
671 rb_reg_expr_str(desc, s,
len, enc, resenc,
'/');
673 option_to_str(opts + 1, options);
681rb_enc_reg_raise(
const char *s,
long len,
rb_encoding *enc,
int options,
const char *
err)
687rb_reg_error_desc(
VALUE str,
int options,
const char *
err)
696rb_reg_raise_str(
VALUE str,
int options,
const char *
err)
714rb_reg_casefold_p(
VALUE re)
746rb_reg_options_m(
VALUE re)
754 int back_num,
int *back_refs,
OnigRegex regex,
void *
arg)
778rb_reg_names(
VALUE re)
789 int back_num,
int *back_refs,
OnigRegex regex,
void *
arg)
795 for (
i = 0;
i < back_num;
i++)
826rb_reg_named_captures(
VALUE re)
835onig_new_with_source(
regex_t** reg,
const UChar* pattern,
const UChar* pattern_end,
837 OnigErrorInfo* einfo,
const char *sourcefile,
int sourceline)
847 r =
onig_compile_ruby(*reg, pattern, pattern_end, einfo, sourcefile, sourceline);
858 const char *sourcefile,
int sourceline)
962pair_byte_cmp(
const void *pair1,
const void *pair2)
964 long diff = ((
pair_t*)pair1)->byte_pos - ((
pair_t*)pair2)->byte_pos;
965#if SIZEOF_LONG > SIZEOF_INT
966 return diff ? diff > 0 ? 1 : -1 : 0;
973update_char_offset(
VALUE match)
1011 qsort(pairs, num_pos,
sizeof(
pair_t), pair_byte_cmp);
1015 for (
i = 0;
i < num_pos;
i++) {
1041match_check(
VALUE match)
1043 if (!
RMATCH(match)->regexp) {
1088match_regexp(
VALUE match)
1092 regexp =
RMATCH(match)->regexp;
1093 if (
NIL_P(regexp)) {
1096 RMATCH(match)->regexp = regexp;
1116match_names(
VALUE match)
1121 return rb_reg_names(
RMATCH(match)->regexp);
1137match_size(
VALUE match)
1143static int name_to_backref_number(
struct re_registers *,
VALUE,
const char*,
const char*);
1154match_backref_number(
VALUE match,
VALUE backref)
1174 name_to_backref_error(backref);
1183 return match_backref_number(match, backref);
1207 int i = match_backref_number(match,
n);
1217 update_char_offset(match);
1243 int i = match_backref_number(match,
n);
1253 update_char_offset(match);
1278 int i = match_backref_number(match,
n);
1288 update_char_offset(match);
1292#define MATCH_BUSY FL_USER2
1310 if (
NIL_P(match))
return -1;
1312 if (!regs)
return -1;
1322 if (!regs)
return FALSE;
1328 if (nth <= 0)
return FALSE;
1330 return (
BEG(nth) != -1);
1339 match->
str = string;
1354 match_set_string(match,
string, pos,
len);
1388rb_reg_fixed_encoding_p(
VALUE re)
1397rb_reg_preprocess(
const char *p,
const char *end,
rb_encoding *enc,
1406 "incompatible encoding regexp match (%s regexp with %s string)",
1425 int cr = str_coderange(
str);
1429 "invalid byte sequence in %s",
1442 reg_enc_error(re,
str);
1444 else if (rb_reg_fixed_encoding_p(re)) {
1447 reg_enc_error(re,
str);
1454 rb_warn(
"historical binary regexp match /.../n against %s string",
1466 const char *pattern;
1471 if (reg->
enc == enc)
return reg;
1477 unescaped = rb_reg_preprocess(
1481 if (unescaped ==
Qnil) {
1512 enc = rb_reg_prepare_enc(re,
str, 0);
1555 if (!tmpreg)
RREGEXP(re)->usecnt++;
1558 if (!
NIL_P(match)) {
1578 if (!tmpreg)
RREGEXP(re)->usecnt--;
1609 if (set_backref_str) {
1613 RMATCH(match)->regexp = re;
1637 if (!tmpreg)
RREGEXP(re)->usecnt++;
1640 if (!
NIL_P(match)) {
1656 if (!tmpreg)
RREGEXP(re)->usecnt--;
1689 RMATCH(match)->regexp = re;
1707 if (nth <= 0)
return Qnil;
1728 if (nth <= 0)
return Qnil;
1731 if (start == -1)
return Qnil;
1765 if (
BEG(0) == -1)
return Qnil;
1792 if (
BEG(0) == -1)
return Qnil;
1808 if (
BEG(0) == -1)
return Qnil;
1812 if (
i == 0)
return Qnil;
1817last_match_getter(
ID _x,
VALUE *_y)
1823prematch_getter(
ID _x,
VALUE *_y)
1829postmatch_getter(
ID _x,
VALUE *_y)
1835last_paren_match_getter(
ID _x,
VALUE *_y)
1841match_array(
VALUE match,
int start)
1851 target =
RMATCH(match)->str;
1854 if (regs->
beg[
i] == -1) {
1889match_to_a(
VALUE match)
1891 return match_array(match, 0);
1908match_captures(
VALUE match)
1910 return match_array(match, 1);
1914name_to_backref_number(
struct re_registers *regs,
VALUE regexp,
const char*
name,
const char* name_end)
1916 if (
NIL_P(regexp))
return -1;
1918 (
const unsigned char *)
name, (
const unsigned char *)name_end, regs);
1921#define NAME_TO_NUMBER(regs, re, name, name_ptr, name_end) \
1923 !rb_enc_compatible(RREGEXP_SRC(re), (name)) ? 0 : \
1924 name_to_backref_number((regs), (re), (name_ptr), (name_end)))
1940 name_to_backref_error(
name);
1951 if (
len == 0)
return result;
1953 for (j =
beg; j <
end; j++) {
1977 return match_ary_subseq(match,
beg,
len, result);
2016 if (
NIL_P(length)) {
2021 int num = namev_to_backref_number(
RMATCH_REGS(match),
RMATCH(match)->regexp, idx);
2026 return match_ary_aref(match, idx,
Qnil);
2047 return match_ary_subseq(match,
beg,
len,
Qnil);
2087 match_ary_aref(match,
argv[
i], result);
2106match_to_s(
VALUE match)
2117 int back_num,
int *back_refs,
OnigRegex regex,
void *
arg) {
2128 for (
i = 0;
i < back_num;
i++) {
2167match_named_captures(
VALUE match)
2195match_string(
VALUE match)
2198 return RMATCH(match)->str;
2208 int back_num,
int *back_refs,
OnigRegex regex,
void *arg0)
2213 for (
i = 0;
i < back_num;
i++) {
2215 arg[back_refs[
i]].len = name_end -
name;
2241match_inspect(
VALUE match)
2254 else if (
NIL_P(regexp)) {
2263 match_inspect_name_iter,
names);
2268 for (
i = 0;
i < num_regs;
i++) {
2295 const char *p = *pp;
2297 int meta_prefix = 0, ctrl_prefix = 0;
2300 if (p == end || *p++ !=
'\\') {
2301 errcpy(
err,
"too short escaped multibyte character");
2307 errcpy(
err,
"too short escape sequence");
2311 case '\\': code =
'\\';
break;
2312 case 'n': code =
'\n';
break;
2313 case 't': code =
'\t';
break;
2314 case 'r': code =
'\r';
break;
2315 case 'f': code =
'\f';
break;
2316 case 'v': code =
'\013';
break;
2317 case 'a': code =
'\007';
break;
2318 case 'e': code =
'\033';
break;
2321 case '0':
case '1':
case '2':
case '3':
2322 case '4':
case '5':
case '6':
case '7':
2343 if (p+1 < end && *p++ ==
'-' && (*p & 0x80) == 0) {
2357 if (p == end || *p++ !=
'-') {
2358 errcpy(
err,
"too short control escape");
2363 errcpy(
err,
"duplicate control escape");
2367 if (p < end && (*p & 0x80) == 0) {
2377 errcpy(
err,
"too short control escape");
2381 errcpy(
err,
"unexpected escape sequence");
2384 if (code < 0 || 0xff < code) {
2399unescape_escaped_nonascii(
const char **pp,
const char *end,
rb_encoding *enc,
2402 const char *p = *pp;
2404 unsigned char *area =
ALLOCA_N(
unsigned char, chmaxlen);
2405 char *chbuf = (
char *)area;
2410 memset(chbuf, 0, chmaxlen);
2412 byte = read_escaped_byte(&p, end,
err);
2417 area[chlen++] = byte;
2418 while (chlen < chmaxlen &&
2420 byte = read_escaped_byte(&p, end,
err);
2424 area[chlen++] = byte;
2429 errcpy(
err,
"invalid multibyte escape");
2432 if (1 < chlen || (area[0] & 0x80)) {
2437 else if (*encp != enc) {
2438 errcpy(
err,
"escaped non ASCII character in UTF-8 regexp");
2444 snprintf(escbuf,
sizeof(escbuf),
"\\x%02X", area[0]&0xff);
2454 if ((0xd800 <= code && code <= 0xdfff) ||
2463append_utf8(
unsigned long uv,
2466 if (check_unicode_range(uv,
err) != 0)
2470 snprintf(escbuf,
sizeof(escbuf),
"\\x%02X", (
int)uv);
2482 errcpy(
err,
"UTF-8 character in non UTF-8 regexp");
2490unescape_unicode_list(
const char **pp,
const char *end,
2493 const char *p = *pp;
2494 int has_unicode = 0;
2498 while (p < end &&
ISSPACE(*p)) p++;
2509 if (append_utf8(code,
buf, encp,
err) != 0)
2513 while (p < end &&
ISSPACE(*p)) p++;
2516 if (has_unicode == 0) {
2527unescape_unicode_bmp(
const char **pp,
const char *end,
2530 const char *p = *pp;
2543 if (append_utf8(code,
buf, encp,
err) != 0)
2550unescape_nonascii(
const char *p,
const char *end,
rb_encoding *enc,
2561 errcpy(
err,
"invalid multibyte character");
2565 if (1 < chlen || (*p & 0x80)) {
2571 else if (*encp != enc) {
2572 errcpy(
err,
"non ASCII character in UTF-8 regexp");
2581 errcpy(
err,
"too short escape sequence");
2586 goto invalid_multibyte;
2595 case '1':
case '2':
case '3':
2596 case '4':
case '5':
case '6':
case '7':
2598 size_t len = end-(p-1), octlen;
2616 const char *pbeg = p;
2617 int byte = read_escaped_byte(&p, end,
err);
2618 if (
byte == -1)
return -1;
2623 if (unescape_escaped_nonascii(&p, end, enc,
buf, encp,
err) != 0)
2630 errcpy(
err,
"too short escape sequence");
2636 if (unescape_unicode_list(&p, end,
buf, encp,
err) != 0)
2638 if (p == end || *p++ !=
'}') {
2646 if (unescape_unicode_bmp(&p, end,
buf, encp,
err) != 0)
2677rb_reg_preprocess(
const char *p,
const char *end,
rb_encoding *enc,
2681 int has_property = 0;
2692 if (unescape_nonascii(p, end, enc,
buf, fixed_enc, &has_property,
err) != 0)
2695 if (has_property && !*fixed_enc) {
2720 buf = rb_reg_preprocess(p, end, enc, &fixed_enc,
err);
2724 return rb_reg_error_desc(
str, 0,
err);
2730rb_reg_preprocess_dregexp(
VALUE ary,
int options)
2751 src_enc != ascii8bit) {
2755 src_enc = ascii8bit;
2762 buf = rb_reg_preprocess(p, end, src_enc, &fixed_enc,
err);
2767 if (fixed_enc != 0) {
2768 if (regexp_enc != 0 && regexp_enc != fixed_enc) {
2772 regexp_enc = fixed_enc;
2790 const char *sourcefile,
int sourceline)
2805 errcpy(
err,
"can't make regexp with dummy encoding");
2809 unescaped = rb_reg_preprocess(s, s+
len, enc, &fixed_enc,
err);
2810 if (unescaped ==
Qnil)
2816 errcpy(
err,
"incompatible character encoding");
2819 if (fixed_enc != a_enc) {
2838 sourcefile, sourceline);
2839 if (!re->
ptr)
return -1;
2848 if (regenc != enc) {
2856 const char *sourcefile,
int sourceline)
2862 if (enc != ascii8bit) {
2864 errcpy(
err,
"/.../n has a non escaped non ASCII character in non ASCII-8BIT script");
2871 options,
err, sourcefile, sourceline);
2872 if (ret == 0) reg_set_source(
obj,
str, str_enc);
2905 if (rb_reg_initialize_str(re, s, options,
err,
NULL, 0) != 0) {
2906 rb_reg_raise_str(s, options,
err);
2918 enc, options,
err,
NULL, 0) != 0) {
2919 rb_reg_raise_str(s, options,
err);
2921 reg_set_source(re, s, enc);
2938 if (rb_reg_initialize(re, s,
len, enc, options,
err,
NULL, 0) != 0) {
2939 rb_enc_reg_raise(s,
len, enc, options,
err);
2959 if (rb_reg_initialize_str(re,
str, options,
err, sourcefile, sourceline) != 0) {
2967static VALUE reg_cache;
2991rb_reg_hash(
VALUE re)
3027 if (re1 == re2)
return Qtrue;
3029 rb_reg_check(re1); rb_reg_check(re2);
3051match_hash(
VALUE match)
3058 hashval =
rb_hash_uint(hashval, reg_hash(match_regexp(match)));
3081 if (match1 == match2)
return Qtrue;
3085 if (!rb_reg_equal(match_regexp(match1), match_regexp(match2)))
return Qfalse;
3095reg_operand(
VALUE s,
int check)
3109reg_match_pos(
VALUE re,
VALUE *strp,
long pos)
3182 long pos = reg_match_pos(re, &
str, 0);
3183 if (pos < 0)
return Qnil;
3303 pos = reg_match_pos(re, &
str, pos);
3353 if (pos < 0)
return Qfalse;
3364 if (!tmpreg)
RREGEXP(re)->usecnt++;
3369 if (!tmpreg)
RREGEXP(re)->usecnt--;
3444 if (kcode[0] ==
'n' || kcode[0] ==
'N') {
3449 rb_warn(
"encoding option is ignored - %s", kcode);
3455 rb_reg_init_str_enc(
self,
str, enc, flags);
3475 s +=
mbclen(s, send, enc);
3479 case '[':
case ']':
case '{':
case '}':
3480 case '(':
case ')':
case '|':
case '-':
3481 case '*':
case '.':
case '\\':
3482 case '?':
case '+':
case '^':
case '$':
3484 case '\t':
case '\f':
case '\v':
case '\n':
case '\r':
3519 case '[':
case ']':
case '{':
case '}':
3520 case '(':
case ')':
case '|':
case '-':
3521 case '*':
case '.':
case '\\':
3522 case '?':
case '+':
case '^':
case '$':
3629 else if (
argc == 1) {
3636 quoted = rb_reg_s_quote(
Qnil,
arg);
3645 int has_asciionly = 0;
3660 if (!has_ascii_incompat)
3661 has_ascii_incompat = enc;
3662 else if (has_ascii_incompat != enc)
3666 else if (rb_reg_fixed_encoding_p(
v)) {
3667 if (!has_ascii_compat_fixed)
3668 has_ascii_compat_fixed = enc;
3669 else if (has_ascii_compat_fixed != enc)
3676 v = rb_reg_str_with_term(
v, -1);
3683 if (!has_ascii_incompat)
3684 has_ascii_incompat = enc;
3685 else if (has_ascii_incompat != enc)
3693 if (!has_ascii_compat_fixed)
3694 has_ascii_compat_fixed = enc;
3695 else if (has_ascii_compat_fixed != enc)
3699 v = rb_reg_s_quote(
Qnil, e);
3701 if (has_ascii_incompat) {
3702 if (has_asciionly) {
3706 if (has_ascii_compat_fixed) {
3718 if (has_ascii_incompat) {
3719 result_enc = has_ascii_incompat;
3721 else if (has_ascii_compat_fixed) {
3722 result_enc = has_ascii_compat_fixed;
3761 return rb_reg_s_union(
self,
v);
3763 return rb_reg_s_union(
self, args);
3784#define ASCGET(s,e,cl) (acompat ? (*(cl)=1,ISASCII((s)[0])?(s)[0]:-1) : rb_enc_ascget((s), (e), (cl), str_enc))
3790 int c =
ASCGET(s, e, &clen);
3794 s +=
mbclen(s, e, str_enc);
3800 if (c !=
'\\' || s == e)
continue;
3809 s +=
mbclen(s, e, str_enc);
3818 case '1':
case '2':
case '3':
case '4':
3819 case '5':
case '6':
case '7':
case '8':
case '9':
3829 if (s < e &&
ASCGET(s, e, &clen) ==
'<') {
3830 char *
name, *name_end;
3832 name_end =
name = s + clen;
3833 while (name_end < e) {
3834 c =
ASCGET(name_end, e, &clen);
3835 if (c ==
'>')
break;
3836 name_end += c == -1 ?
mbclen(name_end, e, str_enc) : clen;
3840 (
long)(name_end -
name));
3842 name_to_backref_error(
n);
3844 p = s = name_end + clen;
3870 while (
BEG(no) == -1 && no > 0) no--;
3871 if (no == 0)
continue;
3884 if (no >= regs->
num_regs)
continue;
3885 if (
BEG(no) == -1)
continue;
3890 if (!val)
return str;
3901 rb_warn(
"variable $KCODE is no longer effective");
3908 rb_warn(
"variable $KCODE is no longer effective; ignored");
3912ignorecase_getter(
ID _x,
VALUE *_y)
3914 rb_warn(
"variable $= is no longer effective");
3921 rb_warn(
"variable $= is no longer effective; ignored");
3935get_LAST_MATCH_INFO(
ID _x,
VALUE *_y)
3937 return match_getter();
3984 n = match_backref_number(match,
argv[0]);
3987 return match_getter();
3991re_warn(
const char *s)
#define range(low, item, hi)
#define ENCINDEX_Windows_31J
int rb_enc_dummy_p(rb_encoding *enc)
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
rb_encoding * rb_utf8_encoding(void)
rb_encoding * rb_ascii8bit_encoding(void)
rb_encoding * rb_default_internal_encoding(void)
int rb_utf8_encindex(void)
rb_encoding * rb_enc_get(VALUE obj)
int rb_ascii8bit_encindex(void)
int rb_enc_unicode_p(rb_encoding *enc)
void rb_enc_copy(VALUE obj1, VALUE obj2)
rb_encoding * rb_default_external_encoding(void)
VALUE rb_obj_encoding(VALUE obj)
rb_encoding * rb_usascii_encoding(void)
VALUE rb_enc_from_encoding(rb_encoding *encoding)
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
#define ENC_CODERANGE_7BIT
#define rb_enc_left_char_head(s, p, e, enc)
#define rb_enc_mbcput(c, buf, enc)
#define ENC_CODERANGE_CLEAN_P(cr)
int rb_enc_str_coderange(VALUE)
#define ENC_CODERANGE(obj)
#define ENC_CODERANGE_UNKNOWN
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
#define rb_enc_mbmaxlen(enc)
#define ENCODING_GET(obj)
#define rb_enc_mbc_to_codepoint(p, e, enc)
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc)
#define MBCLEN_CHARFOUND_LEN(ret)
#define rb_enc_asciicompat(enc)
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts)
int rb_enc_str_asciionly_p(VALUE)
#define MBCLEN_INVALID_P(ret)
#define rb_enc_isprint(c, enc)
#define MBCLEN_NEEDMORE_P(ret)
#define rb_enc_mbminlen(enc)
long rb_enc_strlen(const char *, const char *, rb_encoding *)
#define ENC_CODERANGE_BROKEN
long rb_str_coderange_scan_restartable(const char *, const char *, rb_encoding *, int *)
#define MBCLEN_CHARFOUND_P(ret)
#define rb_enc_isspace(c, enc)
char str[HTML_ESCAPE_MAX_LEN+1]
VALUE rb_define_class(const char *, VALUE)
Defines a top-level class.
void rb_undef_method(VALUE, const char *)
int rb_block_given_p(void)
Determines if the current method is given a block.
VALUE rb_cObject
Object class.
struct re_pattern_buffer * ptr
void rb_raise(VALUE exc, const char *fmt,...)
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_bug(const char *fmt,...)
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
void rb_warn(const char *fmt,...)
VALUE rb_check_convert_type(VALUE, int, const char *, const char *)
Tries to convert an object into another type.
VALUE rb_any_to_s(VALUE)
Default implementation of #to_s.
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Allocates and initializes an instance of klass.
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
verbose(int level, const char *format,...)
#define char_size(c2, c1)
#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s, end)
ONIG_EXTERN int onig_reg_init(OnigRegex reg, OnigOptionType option, OnigCaseFoldType case_fold_flag, OnigEncoding enc, const OnigSyntaxType *syntax)
ONIG_EXTERN int onig_error_code_to_str(OnigUChar *s, OnigPosition err_code,...)
ONIG_EXTERN OnigUChar * onigenc_get_right_adjust_char_head(OnigEncoding enc, const OnigUChar *start, const OnigUChar *s, const OnigUChar *end)
#define ONIG_MAX_ERROR_MESSAGE_LEN
ONIG_EXTERN int onig_new(OnigRegex *, const OnigUChar *pattern, const OnigUChar *pattern_end, OnigOptionType option, OnigEncoding enc, const OnigSyntaxType *syntax, OnigErrorInfo *einfo)
ONIG_EXTERN int onig_region_resize(OnigRegion *region, int n)
ONIG_EXTERN void onig_region_free(OnigRegion *region, int free_self)
#define ONIG_OPTION_MULTILINE
ONIG_EXTERN OnigPosition onig_search(OnigRegex, const OnigUChar *str, const OnigUChar *end, const OnigUChar *start, const OnigUChar *range, OnigRegion *region, OnigOptionType option)
#define ONIGENC_CASE_FOLD_DEFAULT
#define ONIG_OPTION_IGNORECASE
#define ONIG_ENCODING_ASCII
ONIG_EXTERN void onig_free(OnigRegex)
ONIG_EXTERN int onigenc_set_default_encoding(OnigEncoding enc)
ONIG_EXTERN const OnigSyntaxType * OnigDefaultSyntax
#define ONIGENC_MBC_MAXLEN(enc)
ONIG_EXTERN void onig_set_verb_warn_func(OnigWarnFunc f)
ONIG_EXTERN OnigPosition onig_match(OnigRegex, const OnigUChar *str, const OnigUChar *end, const OnigUChar *at, OnigRegion *region, OnigOptionType option)
unsigned int OnigOptionType
ONIG_EXTERN int onig_foreach_name(OnigRegex reg, int(*func)(const OnigUChar *, const OnigUChar *, int, int *, OnigRegex, void *), void *arg)
ONIG_EXTERN void onig_region_copy(OnigRegion *to, const OnigRegion *from)
ONIG_EXTERN int onig_name_to_backref_number(OnigRegex reg, const OnigUChar *name, const OnigUChar *name_end, const OnigRegion *region)
ONIG_EXTERN int onig_noname_group_capture_is_active(const OnigRegexType *reg)
#define ONIG_OPTION_EXTEND
ONIG_EXTERN int onig_number_of_names(const OnigRegexType *reg)
ONIG_EXTERN void onig_set_warn_func(OnigWarnFunc f)
int rb_reg_backref_number(VALUE match, VALUE backref)
void rb_backref_set_string(VALUE string, long pos, long len)
VALUE rb_reg_nth_defined(int nth, VALUE match)
NORETURN(static void rb_reg_raise(const char *s, long len, const char *err, VALUE re))
VALUE rb_reg_match_last(VALUE match)
int rb_reg_options(VALUE re)
VALUE rb_reg_match(VALUE re, VALUE str)
#define REG_ENCODING_NONE
VALUE rb_reg_eqq(VALUE re, VALUE str)
#define NAME_TO_NUMBER(regs, re, name, name_ptr, name_end)
regex_t * rb_reg_prepare_re(VALUE re, VALUE str)
VALUE rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
#define ARG_ENCODING_NONE
VALUE rb_enc_reg_new(const char *s, long len, rb_encoding *enc, int options)
#define ARG_ENCODING_FIXED
VALUE rb_reg_match_post(VALUE match)
VALUE rb_reg_last_match(VALUE match)
VALUE rb_reg_match_p(VALUE re, VALUE str, long pos)
VALUE rb_reg_match_pre(VALUE match)
char onig_errmsg_buffer[ONIG_MAX_ERROR_MESSAGE_LEN]
VALUE rb_reg_new(const char *s, long len, int options)
bool rb_reg_start_with_p(VALUE re, VALUE str)
int rb_char_to_option_kcode(int c, int *option, int *kcode)
void rb_match_busy(VALUE match)
long rb_memsearch(const void *x0, long m, const void *y0, long n, rb_encoding *enc)
regex_t * rb_reg_prepare_re0(VALUE re, VALUE str, onig_errmsg_buffer err)
#define ARG_REG_OPTION_MASK
long rb_reg_search(VALUE re, VALUE str, long pos, int reverse)
long rb_reg_adjust_startpos(VALUE re, VALUE str, long pos, int reverse)
VALUE rb_reg_regcomp(VALUE str)
VALUE rb_reg_nth_match(int nth, VALUE match)
int rb_match_nth_defined(int nth, VALUE match)
long rb_reg_search0(VALUE re, VALUE str, long pos, int reverse, int set_backref_str)
MJIT_FUNC_EXPORTED VALUE rb_reg_new_ary(VALUE ary, int opt)
int rb_memcicmp(const void *x, const void *y, long len)
VALUE rb_reg_init_str(VALUE re, VALUE s, int options)
VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline)
void rb_match_unbusy(VALUE match)
int rb_match_count(VALUE match)
VALUE rb_reg_match2(VALUE re)
VALUE rb_reg_quote(VALUE str)
VALUE rb_check_regexp_type(VALUE re)
VALUE rb_reg_check_preprocess(VALUE str)
VALUE rb_reg_new_str(VALUE s, int options)
int rb_reg_region_copy(struct re_registers *to, const struct re_registers *from)
typedefRUBY_SYMBOL_EXPORT_BEGIN struct re_pattern_buffer Regexp
int onig_compile_ruby(regex_t *reg, const UChar *pattern, const UChar *pattern_end, OnigErrorInfo *einfo, const char *sourcefile, int sourceline)
#define mbclen(p, e, enc)
int char_offset_num_allocated
struct rmatch_offset * char_offset
unsigned long ruby_scan_oct(const char *, size_t, size_t *)
unsigned long ruby_scan_hex(const char *, size_t, size_t *)
#define scan_hex(s, l, e)
#define scan_oct(s, l, e)