Ruby
2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)
|
Go to the documentation of this file.
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)])
29 static 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++]))
94 rb_memsearch_ss(
const unsigned char *xs,
long m,
const unsigned char *ys,
long n)
96 const unsigned char *y;
105 rb_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) {
139 rb_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)
158 static inline unsigned int
159 rb_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;
191 rb_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)
213 rb_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)
226 rb_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
286 char_to_option(
int c)
308 option_to_str(
char str[4],
int options)
338 return (*option = char_to_option(c));
345 rb_reg_check(
VALUE re)
353 rb_reg_expr_str(
VALUE str,
const char *s,
long len,
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);
442 rb_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))
484 rb_reg_source(
VALUE re)
506 rb_reg_inspect(
VALUE re)
537 rb_reg_to_s(
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);
654 rb_reg_raise(
const char *s,
long len,
const char *
err,
VALUE re)
656 VALUE desc = rb_reg_desc(s,
len, re);
662 rb_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);
681 rb_enc_reg_raise(
const char *s,
long len,
rb_encoding *enc,
int options,
const char *
err)
687 rb_reg_error_desc(
VALUE str,
int options,
const char *
err)
696 rb_reg_raise_str(
VALUE str,
int options,
const char *
err)
714 rb_reg_casefold_p(
VALUE re)
746 rb_reg_options_m(
VALUE re)
754 int back_num,
int *back_refs,
OnigRegex regex,
void *
arg)
778 rb_reg_names(
VALUE re)
789 int back_num,
int *back_refs,
OnigRegex regex,
void *
arg)
795 for (
i = 0;
i < back_num;
i++)
826 rb_reg_named_captures(
VALUE re)
835 onig_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)
962 pair_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;
973 update_char_offset(
VALUE match)
1011 qsort(pairs, num_pos,
sizeof(
pair_t), pair_byte_cmp);
1015 for (
i = 0;
i < num_pos;
i++) {
1041 match_check(
VALUE match)
1043 if (!
RMATCH(match)->regexp) {
1088 match_regexp(
VALUE match)
1092 regexp =
RMATCH(match)->regexp;
1093 if (
NIL_P(regexp)) {
1096 RMATCH(match)->regexp = regexp;
1116 match_names(
VALUE match)
1121 return rb_reg_names(
RMATCH(match)->regexp);
1137 match_size(
VALUE match)
1143 static int name_to_backref_number(
struct re_registers *,
VALUE,
const char*,
const char*);
1146 match_backref_number(
VALUE match,
VALUE backref)
1175 return match_backref_number(match, backref);
1199 int i = match_backref_number(match,
n);
1209 update_char_offset(match);
1235 int i = match_backref_number(match,
n);
1245 update_char_offset(match);
1270 int i = match_backref_number(match,
n);
1280 update_char_offset(match);
1284 #define MATCH_BUSY FL_USER2
1302 if (
NIL_P(match))
return -1;
1304 if (!regs)
return -1;
1314 if (!regs)
return FALSE;
1320 if (nth <= 0)
return FALSE;
1322 return (
BEG(nth) != -1);
1331 match->
str = string;
1346 match_set_string(match,
string, pos,
len);
1380 rb_reg_fixed_encoding_p(
VALUE re)
1389 rb_reg_preprocess(
const char *p,
const char *end,
rb_encoding *enc,
1398 "incompatible encoding regexp match (%s regexp with %s string)",
1417 int cr = str_coderange(
str);
1421 "invalid byte sequence in %s",
1434 reg_enc_error(re,
str);
1436 else if (rb_reg_fixed_encoding_p(re)) {
1439 reg_enc_error(re,
str);
1446 rb_warn(
"historical binary regexp match /.../n against %s string",
1458 const char *pattern;
1463 if (reg->
enc == enc)
return reg;
1469 unescaped = rb_reg_preprocess(
1473 if (unescaped ==
Qnil) {
1504 enc = rb_reg_prepare_enc(re,
str, 0);
1547 if (!tmpreg)
RREGEXP(re)->usecnt++;
1550 if (!
NIL_P(match)) {
1570 if (!tmpreg)
RREGEXP(re)->usecnt--;
1601 if (set_backref_str) {
1605 RMATCH(match)->regexp = re;
1629 if (!tmpreg)
RREGEXP(re)->usecnt++;
1632 if (!
NIL_P(match)) {
1648 if (!tmpreg)
RREGEXP(re)->usecnt--;
1681 RMATCH(match)->regexp = re;
1699 if (nth <= 0)
return Qnil;
1720 if (nth <= 0)
return Qnil;
1723 if (start == -1)
return Qnil;
1757 if (
BEG(0) == -1)
return Qnil;
1784 if (
BEG(0) == -1)
return Qnil;
1800 if (
BEG(0) == -1)
return Qnil;
1804 if (
i == 0)
return Qnil;
1809 last_match_getter(
ID _x,
VALUE *_y)
1815 prematch_getter(
ID _x,
VALUE *_y)
1821 postmatch_getter(
ID _x,
VALUE *_y)
1827 last_paren_match_getter(
ID _x,
VALUE *_y)
1833 match_array(
VALUE match,
int start)
1843 target =
RMATCH(match)->str;
1846 if (regs->
beg[
i] == -1) {
1881 match_to_a(
VALUE match)
1883 return match_array(match, 0);
1900 match_captures(
VALUE match)
1902 return match_array(match, 1);
1906 name_to_backref_number(
struct re_registers *regs,
VALUE regexp,
const char*
name,
const char* name_end)
1909 (
const unsigned char *)
name, (
const unsigned char *)name_end, regs);
1920 #define NAME_TO_NUMBER(regs, re, name, name_ptr, name_end) \
1922 !rb_enc_compatible(RREGEXP_SRC(re), (name)) ? 0 : \
1923 name_to_backref_number((regs), (re), (name_ptr), (name_end)))
1939 name_to_backref_error(
name);
1950 if (
len == 0)
return result;
1952 for (j =
beg; j <
end; j++) {
1976 return match_ary_subseq(match,
beg,
len, result);
2015 if (
NIL_P(length)) {
2020 int num = namev_to_backref_number(
RMATCH_REGS(match),
RMATCH(match)->regexp, idx);
2025 return match_ary_aref(match, idx,
Qnil);
2046 return match_ary_subseq(match,
beg,
len,
Qnil);
2086 match_ary_aref(match,
argv[
i], result);
2105 match_to_s(
VALUE match)
2116 int back_num,
int *back_refs,
OnigRegex regex,
void *
arg) {
2127 for (
i = 0;
i < back_num;
i++) {
2166 match_named_captures(
VALUE match)
2194 match_string(
VALUE match)
2197 return RMATCH(match)->str;
2207 int back_num,
int *back_refs,
OnigRegex regex,
void *arg0)
2212 for (
i = 0;
i < back_num;
i++) {
2214 arg[back_refs[
i]].len = name_end -
name;
2240 match_inspect(
VALUE match)
2253 else if (
NIL_P(regexp)) {
2262 match_inspect_name_iter,
names);
2267 for (
i = 0;
i < num_regs;
i++) {
2294 const char *p = *pp;
2296 int meta_prefix = 0, ctrl_prefix = 0;
2299 if (p == end || *p++ !=
'\\') {
2300 errcpy(
err,
"too short escaped multibyte character");
2306 errcpy(
err,
"too short escape sequence");
2310 case '\\': code =
'\\';
break;
2311 case 'n': code =
'\n';
break;
2312 case 't': code =
'\t';
break;
2313 case 'r': code =
'\r';
break;
2314 case 'f': code =
'\f';
break;
2315 case 'v': code =
'\013';
break;
2316 case 'a': code =
'\007';
break;
2317 case 'e': code =
'\033';
break;
2320 case '0':
case '1':
case '2':
case '3':
2321 case '4':
case '5':
case '6':
case '7':
2342 if (p+1 < end && *p++ ==
'-' && (*p & 0x80) == 0) {
2356 if (p == end || *p++ !=
'-') {
2357 errcpy(
err,
"too short control escape");
2362 errcpy(
err,
"duplicate control escape");
2366 if (p < end && (*p & 0x80) == 0) {
2376 errcpy(
err,
"too short control escape");
2380 errcpy(
err,
"unexpected escape sequence");
2383 if (code < 0 || 0xff < code) {
2398 unescape_escaped_nonascii(
const char **pp,
const char *end,
rb_encoding *enc,
2401 const char *p = *pp;
2403 unsigned char *area =
ALLOCA_N(
unsigned char, chmaxlen);
2404 char *chbuf = (
char *)area;
2409 memset(chbuf, 0, chmaxlen);
2411 byte = read_escaped_byte(&p, end,
err);
2416 area[chlen++] = byte;
2417 while (chlen < chmaxlen &&
2419 byte = read_escaped_byte(&p, end,
err);
2423 area[chlen++] = byte;
2428 errcpy(
err,
"invalid multibyte escape");
2431 if (1 < chlen || (area[0] & 0x80)) {
2436 else if (*encp != enc) {
2437 errcpy(
err,
"escaped non ASCII character in UTF-8 regexp");
2443 snprintf(escbuf,
sizeof(escbuf),
"\\x%02X", area[0]&0xff);
2453 if ((0xd800 <= code && code <= 0xdfff) ||
2462 append_utf8(
unsigned long uv,
2465 if (check_unicode_range(uv,
err) != 0)
2469 snprintf(escbuf,
sizeof(escbuf),
"\\x%02X", (
int)uv);
2481 errcpy(
err,
"UTF-8 character in non UTF-8 regexp");
2489 unescape_unicode_list(
const char **pp,
const char *end,
2492 const char *p = *pp;
2493 int has_unicode = 0;
2497 while (p < end &&
ISSPACE(*p)) p++;
2508 if (append_utf8(code,
buf, encp,
err) != 0)
2512 while (p < end &&
ISSPACE(*p)) p++;
2515 if (has_unicode == 0) {
2526 unescape_unicode_bmp(
const char **pp,
const char *end,
2529 const char *p = *pp;
2542 if (append_utf8(code,
buf, encp,
err) != 0)
2549 unescape_nonascii(
const char *p,
const char *end,
rb_encoding *enc,
2560 errcpy(
err,
"invalid multibyte character");
2564 if (1 < chlen || (*p & 0x80)) {
2570 else if (*encp != enc) {
2571 errcpy(
err,
"non ASCII character in UTF-8 regexp");
2580 errcpy(
err,
"too short escape sequence");
2585 goto invalid_multibyte;
2594 case '1':
case '2':
case '3':
2595 case '4':
case '5':
case '6':
case '7':
2597 size_t len = end-(p-1), octlen;
2615 const char *pbeg = p;
2616 int byte = read_escaped_byte(&p, end,
err);
2617 if (
byte == -1)
return -1;
2622 if (unescape_escaped_nonascii(&p, end, enc,
buf, encp,
err) != 0)
2629 errcpy(
err,
"too short escape sequence");
2635 if (unescape_unicode_list(&p, end,
buf, encp,
err) != 0)
2637 if (p == end || *p++ !=
'}') {
2645 if (unescape_unicode_bmp(&p, end,
buf, encp,
err) != 0)
2676 rb_reg_preprocess(
const char *p,
const char *end,
rb_encoding *enc,
2680 int has_property = 0;
2691 if (unescape_nonascii(p, end, enc,
buf, fixed_enc, &has_property,
err) != 0)
2694 if (has_property && !*fixed_enc) {
2719 buf = rb_reg_preprocess(p, end, enc, &fixed_enc,
err);
2723 return rb_reg_error_desc(
str, 0,
err);
2729 rb_reg_preprocess_dregexp(
VALUE ary,
int options)
2750 src_enc != ascii8bit) {
2754 src_enc = ascii8bit;
2761 buf = rb_reg_preprocess(p, end, src_enc, &fixed_enc,
err);
2766 if (fixed_enc != 0) {
2767 if (regexp_enc != 0 && regexp_enc != fixed_enc) {
2771 regexp_enc = fixed_enc;
2789 const char *sourcefile,
int sourceline)
2804 errcpy(
err,
"can't make regexp with dummy encoding");
2808 unescaped = rb_reg_preprocess(s, s+
len, enc, &fixed_enc,
err);
2809 if (unescaped ==
Qnil)
2815 errcpy(
err,
"incompatible character encoding");
2818 if (fixed_enc != a_enc) {
2837 sourcefile, sourceline);
2838 if (!re->
ptr)
return -1;
2847 if (regenc != enc) {
2855 const char *sourcefile,
int sourceline)
2861 if (enc != ascii8bit) {
2863 errcpy(
err,
"/.../n has a non escaped non ASCII character in non ASCII-8BIT script");
2870 options,
err, sourcefile, sourceline);
2871 if (ret == 0) reg_set_source(
obj,
str, str_enc);
2904 if (rb_reg_initialize_str(re, s, options,
err,
NULL, 0) != 0) {
2905 rb_reg_raise_str(s, options,
err);
2917 enc, options,
err,
NULL, 0) != 0) {
2918 rb_reg_raise_str(s, options,
err);
2920 reg_set_source(re, s, enc);
2937 if (rb_reg_initialize(re, s,
len, enc, options,
err,
NULL, 0) != 0) {
2938 rb_enc_reg_raise(s,
len, enc, options,
err);
2958 if (rb_reg_initialize_str(re,
str, options,
err, sourcefile, sourceline) != 0) {
2966 static VALUE reg_cache;
2990 rb_reg_hash(
VALUE re)
3026 if (re1 == re2)
return Qtrue;
3028 rb_reg_check(re1); rb_reg_check(re2);
3050 match_hash(
VALUE match)
3057 hashval =
rb_hash_uint(hashval, reg_hash(match_regexp(match)));
3080 if (match1 == match2)
return Qtrue;
3084 if (!rb_reg_equal(match_regexp(match1), match_regexp(match2)))
return Qfalse;
3094 reg_operand(
VALUE s,
int check)
3108 reg_match_pos(
VALUE re,
VALUE *strp,
long pos)
3181 long pos = reg_match_pos(re, &
str, 0);
3182 if (pos < 0)
return Qnil;
3302 pos = reg_match_pos(re, &
str, pos);
3352 if (pos < 0)
return Qfalse;
3363 if (!tmpreg)
RREGEXP(re)->usecnt++;
3368 if (!tmpreg)
RREGEXP(re)->usecnt--;
3443 if (kcode[0] ==
'n' || kcode[0] ==
'N') {
3448 rb_warn(
"encoding option is ignored - %s", kcode);
3454 rb_reg_init_str_enc(
self,
str, enc, flags);
3474 s +=
mbclen(s, send, enc);
3478 case '[':
case ']':
case '{':
case '}':
3479 case '(':
case ')':
case '|':
case '-':
3480 case '*':
case '.':
case '\\':
3481 case '?':
case '+':
case '^':
case '$':
3483 case '\t':
case '\f':
case '\v':
case '\n':
case '\r':
3518 case '[':
case ']':
case '{':
case '}':
3519 case '(':
case ')':
case '|':
case '-':
3520 case '*':
case '.':
case '\\':
3521 case '?':
case '+':
case '^':
case '$':
3628 else if (
argc == 1) {
3635 quoted = rb_reg_s_quote(
Qnil,
arg);
3644 int has_asciionly = 0;
3659 if (!has_ascii_incompat)
3660 has_ascii_incompat = enc;
3661 else if (has_ascii_incompat != enc)
3665 else if (rb_reg_fixed_encoding_p(
v)) {
3666 if (!has_ascii_compat_fixed)
3667 has_ascii_compat_fixed = enc;
3668 else if (has_ascii_compat_fixed != enc)
3675 v = rb_reg_str_with_term(
v, -1);
3682 if (!has_ascii_incompat)
3683 has_ascii_incompat = enc;
3684 else if (has_ascii_incompat != enc)
3692 if (!has_ascii_compat_fixed)
3693 has_ascii_compat_fixed = enc;
3694 else if (has_ascii_compat_fixed != enc)
3698 v = rb_reg_s_quote(
Qnil, e);
3700 if (has_ascii_incompat) {
3701 if (has_asciionly) {
3705 if (has_ascii_compat_fixed) {
3717 if (has_ascii_incompat) {
3718 result_enc = has_ascii_incompat;
3720 else if (has_ascii_compat_fixed) {
3721 result_enc = has_ascii_compat_fixed;
3760 return rb_reg_s_union(
self,
v);
3762 return rb_reg_s_union(
self, args);
3783 #define ASCGET(s,e,cl) (acompat ? (*(cl)=1,ISASCII((s)[0])?(s)[0]:-1) : rb_enc_ascget((s), (e), (cl), str_enc))
3789 int c =
ASCGET(s, e, &clen);
3793 s +=
mbclen(s, e, str_enc);
3799 if (c !=
'\\' || s == e)
continue;
3808 s +=
mbclen(s, e, str_enc);
3817 case '1':
case '2':
case '3':
case '4':
3818 case '5':
case '6':
case '7':
case '8':
case '9':
3828 if (s < e &&
ASCGET(s, e, &clen) ==
'<') {
3829 char *
name, *name_end;
3831 name_end =
name = s + clen;
3832 while (name_end < e) {
3833 c =
ASCGET(name_end, e, &clen);
3834 if (c ==
'>')
break;
3835 name_end += c == -1 ?
mbclen(name_end, e, str_enc) : clen;
3839 (
long)(name_end -
name));
3841 name_to_backref_error(
n);
3843 p = s = name_end + clen;
3869 while (
BEG(no) == -1 && no > 0) no--;
3870 if (no == 0)
continue;
3883 if (no >= regs->
num_regs)
continue;
3884 if (
BEG(no) == -1)
continue;
3889 if (!val)
return str;
3898 kcode_getter(
ID _x,
VALUE *_y)
3900 rb_warn(
"variable $KCODE is no longer effective");
3907 rb_warn(
"variable $KCODE is no longer effective; ignored");
3911 ignorecase_getter(
ID _x,
VALUE *_y)
3913 rb_warn(
"variable $= is no longer effective");
3920 rb_warn(
"variable $= is no longer effective; ignored");
3934 get_LAST_MATCH_INFO(
ID _x,
VALUE *_y)
3936 return match_getter();
3983 n = match_backref_number(match,
argv[0]);
3986 return match_getter();
3990 re_warn(
const char *s)
void rb_match_unbusy(VALUE match)
VALUE rb_ary_new_capa(long capa)
VALUE rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
VALUE rb_reg_eqq(VALUE re, VALUE str)
#define NAME_TO_NUMBER(regs, re, name, name_ptr, name_end)
int rb_enc_unicode_p(rb_encoding *enc)
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc)
VALUE rb_assoc_new(VALUE car, VALUE cdr)
ONIG_EXTERN int onig_error_code_to_str(OnigUChar *s, OnigPosition err_code,...)
#define rb_enc_mbc_to_codepoint(p, e, enc)
st_index_t rb_str_hash(VALUE)
#define range(low, item, hi)
#define rb_enc_mbcput(c, buf, enc)
#define ONIG_OPTION_IGNORECASE
VALUE rb_str_buf_new(long)
void rb_warn(const char *fmt,...)
int onig_compile_ruby(regex_t *reg, const UChar *pattern, const UChar *pattern_end, OnigErrorInfo *einfo, const char *sourcefile, int sourceline)
int rb_block_given_p(void)
Determines if the current method is given a block.
long rb_enc_strlen(const char *, const char *, rb_encoding *)
VALUE rb_str_buf_cat_ascii(VALUE, const char *)
NORETURN(static void rb_reg_raise(const char *s, long len, const char *err, VALUE re))
long rb_reg_search(VALUE re, VALUE str, long pos, int reverse)
VALUE rb_reg_match2(VALUE re)
#define RREGEXP_SRC_LEN(r)
int rb_utf8_encindex(void)
rb_encoding * rb_default_external_encoding(void)
VALUE rb_obj_encoding(VALUE obj)
VALUE rb_reg_nth_defined(int nth, VALUE match)
void rb_ary_store(VALUE ary, long idx, VALUE val)
#define RB_TYPE_P(obj, type)
rb_encoding * rb_enc_get(VALUE obj)
#define rb_enc_asciicompat(enc)
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
VALUE rb_check_convert_type(VALUE, int, const char *, const char *)
Tries to convert an object into another type.
VALUE rb_str_length(VALUE)
#define scan_oct(s, l, e)
#define REG_ENCODING_NONE
struct re_pattern_buffer * ptr
VALUE rb_check_string_type(VALUE)
struct rmatch_offset * char_offset
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
typedefRUBY_SYMBOL_EXPORT_BEGIN struct re_pattern_buffer Regexp
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
int rb_enc_dummy_p(rb_encoding *enc)
ONIG_EXTERN int onig_region_resize(OnigRegion *region, int n)
VALUE rb_str_inspect(VALUE)
unsigned long ruby_scan_oct(const char *, size_t, size_t *)
ONIG_EXTERN int onig_name_to_backref_number(OnigRegex reg, const OnigUChar *name, const OnigUChar *name_end, const OnigRegion *region)
ONIG_EXTERN OnigPosition onig_search(OnigRegex, const OnigUChar *str, const OnigUChar *end, const OnigUChar *start, const OnigUChar *range, OnigRegion *region, OnigOptionType option)
int rb_reg_backref_number(VALUE match, VALUE backref)
#define rb_enc_mbmaxlen(enc)
#define ARG_ENCODING_FIXED
#define ONIGENC_MBC_MAXLEN(enc)
char onig_errmsg_buffer[ONIG_MAX_ERROR_MESSAGE_LEN]
VALUE rb_enc_from_encoding(rb_encoding *encoding)
ONIG_EXTERN OnigPosition onig_match(OnigRegex, const OnigUChar *str, const OnigUChar *end, const OnigUChar *at, OnigRegion *region, OnigOptionType option)
size_t strlen(const char *)
int rb_ascii8bit_encindex(void)
VALUE rb_reg_new(const char *s, long len, int options)
#define ONIG_ENCODING_ASCII
void rb_undef_method(VALUE klass, const char *name)
VALUE rb_reg_quote(VALUE str)
st_index_t rb_memhash(const void *ptr, long len)
ONIG_EXTERN void onig_region_free(OnigRegion *region, int free_self)
MJIT_FUNC_EXPORTED VALUE rb_hash_new_with_size(st_index_t size)
long rb_reg_search0(VALUE re, VALUE str, long pos, int reverse, int set_backref_str)
#define MBCLEN_INVALID_P(ret)
VALUE rb_str_resize(VALUE, long)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_ary_entry(VALUE ary, long offset)
ONIG_EXTERN int onig_foreach_name(OnigRegex reg, int(*func)(const OnigUChar *, const OnigUChar *, int, int *, OnigRegex, void *), void *arg)
int rb_reg_options(VALUE re)
VALUE rb_reg_match_pre(VALUE match)
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
ONIG_EXTERN void onig_free(OnigRegex)
VALUE rb_reg_last_match(VALUE match)
int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p)
rb_encoding * rb_ascii8bit_encoding(void)
VALUE rb_reg_match(VALUE re, VALUE str)
#define MBCLEN_CHARFOUND_LEN(ret)
const typedef OnigEncodingType rb_encoding
#define rb_check_frozen(obj)
#define rb_enc_left_char_head(s, p, e, enc)
bool rb_reg_start_with_p(VALUE re, VALUE str)
VALUE rb_reg_check_preprocess(VALUE str)
VALUE rb_reg_match_p(VALUE re, VALUE str, long pos)
ONIG_EXTERN void onig_region_copy(OnigRegion *to, const OnigRegion *from)
VALUE rb_str_equal(VALUE str1, VALUE str2)
VALUE rb_ary_push(VALUE ary, VALUE item)
st_index_t rb_hash_start(st_index_t)
#define rb_enc_mbminlen(enc)
#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s, end)
#define ONIG_OPTION_MULTILINE
unsigned int OnigOptionType
unsigned long ruby_scan_hex(const char *, size_t, size_t *)
long rb_reg_adjust_startpos(VALUE re, VALUE str, long pos, int reverse)
#define MEMO_NEW(a, b, c)
#define ALLOCA_N(type, n)
#define RARRAY_AREF(a, i)
ONIG_EXTERN int onigenc_set_default_encoding(OnigEncoding enc)
#define StringValuePtr(v)
void rb_enc_copy(VALUE obj1, VALUE obj2)
VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline)
ONIG_EXTERN int onig_number_of_names(const OnigRegexType *reg)
MJIT_FUNC_EXPORTED VALUE rb_reg_new_ary(VALUE ary, int opt)
VALUE rb_backref_get(void)
VALUE rb_ary_resize(VALUE ary, long len)
expands or shrinks ary to len elements.
int rb_char_to_option_kcode(int c, int *option, int *kcode)
#define MBCLEN_NEEDMORE_P(ret)
const typedef OnigEncodingType * OnigEncoding
long rb_memsearch(const void *x0, long m, const void *y0, long n, rb_encoding *enc)
#define MEMZERO(p, type, n)
int memcmp(const void *s1, const void *s2, size_t len)
ONIG_EXTERN int onig_reg_init(OnigRegex reg, OnigOptionType option, OnigCaseFoldType case_fold_flag, OnigEncoding enc, const OnigSyntaxType *syntax)
void rb_backref_set(VALUE)
#define mbclen(p, e, enc)
rb_encoding * rb_default_internal_encoding(void)
void rb_backref_set_string(VALUE string, long pos, long len)
#define RB_OBJ_WRITE(a, slot, b)
void rb_match_busy(VALUE match)
VALUE rb_reg_regcomp(VALUE str)
#define StringValueCStr(v)
#define ENC_CODERANGE_BROKEN
VALUE rb_check_array_type(VALUE ary)
VALUE rb_lastline_get(void)
void rb_global_variable(VALUE *var)
VALUE rb_str_buf_append(VALUE, VALUE)
VALUE rb_str_to_str(VALUE)
#define MBCLEN_CHARFOUND_P(ret)
ONIG_EXTERN void onig_set_verb_warn_func(OnigWarnFunc f)
RUBY_EXTERN VALUE rb_cObject
int rb_uv_to_utf8(char[6], unsigned long)
unsigned char buf[MIME_BUF_SIZE]
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
VALUE rb_str_append(VALUE, VALUE)
int rb_enc_str_coderange(VALUE)
void rb_bug(const char *fmt,...)
int char_offset_num_allocated
#define scan_hex(s, l, e)
#define OBJ_INIT_COPY(obj, orig)
#define RGENGC_WB_PROTECTED_REGEXP
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
#define rb_hash_uint(h, i)
char * rb_str_subpos(VALUE, long, long *)
#define ENCODING_GET(obj)
#define ONIG_MAX_ERROR_MESSAGE_LEN
VALUE rb_sprintf(const char *format,...)
VALUE rb_range_beg_len(VALUE, long *, long *, long, int)
VALUE rb_str_subseq(VALUE, long, long)
int rb_reg_region_copy(struct re_registers *to, const struct re_registers *from)
rb_encoding * rb_utf8_encoding(void)
char str[HTML_ESCAPE_MAX_LEN+1]
#define RREGEXP_SRC_PTR(r)
ONIG_EXTERN void onig_set_warn_func(OnigWarnFunc f)
regex_t * rb_reg_prepare_re0(VALUE re, VALUE str, onig_errmsg_buffer err)
#define ENC_CODERANGE_7BIT
#define MEMCPY(p1, p2, type, n)
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
int rb_match_nth_defined(int nth, VALUE match)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
VALUE rb_reg_init_str(VALUE re, VALUE s, int options)
ONIG_EXTERN int onig_new(OnigRegex *, const OnigUChar *pattern, const OnigUChar *pattern_end, OnigOptionType option, OnigEncoding enc, const OnigSyntaxType *syntax, OnigErrorInfo *einfo)
ONIG_EXTERN OnigUChar * onigenc_get_right_adjust_char_head(OnigEncoding enc, const OnigUChar *start, const OnigUChar *s, const OnigUChar *end)
#define REALLOC_N(var, type, n)
void rb_define_const(VALUE, const char *, VALUE)
#define ONIGENC_CASE_FOLD_DEFAULT
#define ARG_REG_OPTION_MASK
int rb_memcicmp(const void *x, const void *y, long len)
regex_t * rb_reg_prepare_re(VALUE re, VALUE str)
#define MJIT_FUNC_EXPORTED
VALUE rb_str_catf(VALUE str, const char *format,...)
VALUE rb_class_path(VALUE)
VALUE rb_reg_match_post(VALUE match)
#define ENC_CODERANGE(obj)
VALUE rb_enc_reg_new(const char *s, long len, rb_encoding *enc, int options)
#define ENCINDEX_Windows_31J
VALUE rb_reg_new_str(VALUE s, int options)
#define ARG_ENCODING_NONE
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Allocates and initializes an instance of klass.
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts)
VALUE rb_reg_nth_match(int nth, VALUE match)
int rb_enc_str_asciionly_p(VALUE)
#define NEWOBJ_OF(obj, type, klass, flags)
void rb_define_virtual_variable(const char *q, type *w, void_type *e)
Define a function-backended global variable.
VALUE rb_check_regexp_type(VALUE re)
VALUE rb_reg_match_last(VALUE match)
#define rb_enc_isprint(c, enc)
long rb_str_coderange_scan_restartable(const char *, const char *, rb_encoding *, int *)
int rb_match_count(VALUE match)
VALUE rb_any_to_s(VALUE)
Default implementation of #to_s.
#define rb_enc_isspace(c, enc)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
#define ENC_CODERANGE_UNKNOWN
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
ONIG_EXTERN int onig_noname_group_capture_is_active(const OnigRegexType *reg)
#define ENC_CODERANGE_CLEAN_P(cr)
#define char_size(c2, c1)
#define ONIG_OPTION_EXTEND
long rb_str_offset(VALUE, long)
long rb_str_sublen(VALUE, long)
rb_encoding * rb_usascii_encoding(void)
verbose(int level, const char *format,...)
const ONIG_EXTERN OnigSyntaxType * OnigDefaultSyntax