Bug #9676 ยป ruby-578.diff
include/ruby/re.h | ||
---|---|---|
#define RMATCH_REGS(obj) (&(R_CAST(RMatch)(obj))->rmatch->regs)
|
||
VALUE rb_reg_regcomp(VALUE);
|
||
long rb_reg_search0(VALUE, VALUE, long, int, int);
|
||
long rb_reg_search(VALUE, VALUE, long, int);
|
||
VALUE rb_reg_regsub(VALUE, VALUE, struct re_registers *, VALUE);
|
||
long rb_reg_adjust_startpos(VALUE, VALUE, long, int);
|
re.c | ||
---|---|---|
/* returns byte offset */
|
||
long
|
||
rb_reg_search(VALUE re, VALUE str, long pos, int reverse)
|
||
rb_reg_search0(VALUE re, VALUE str, long pos, int reverse, int set_backref_str)
|
||
{
|
||
long result;
|
||
VALUE match;
|
||
... | ... | |
FL_UNSET(match, FL_TAINT);
|
||
}
|
||
RMATCH(match)->str = rb_str_new4(str);
|
||
if (set_backref_str) {
|
||
RMATCH(match)->str = rb_str_new4(str);
|
||
OBJ_INFECT(match, str);
|
||
}
|
||
RMATCH(match)->regexp = re;
|
||
RMATCH(match)->rmatch->char_offset_updated = 0;
|
||
rb_backref_set(match);
|
||
OBJ_INFECT(match, re);
|
||
OBJ_INFECT(match, str);
|
||
return result;
|
||
}
|
||
long
|
||
rb_reg_search(VALUE re, VALUE str, long pos, int reverse)
|
||
{
|
||
return rb_reg_search0(re, str, pos, reverse, 1);
|
||
}
|
||
VALUE
|
||
rb_reg_nth_defined(int nth, VALUE match)
|
||
{
|
string.c | ||
---|---|---|
int iter = 0;
|
||
char *sp, *cp;
|
||
int tainted = 0;
|
||
int str_replace;
|
||
rb_encoding *str_enc;
|
||
switch (argc) {
|
||
... | ... | |
}
|
||
pat = get_pat(argv[0], 1);
|
||
beg = rb_reg_search(pat, str, 0, 0);
|
||
str_replace = !iter && NIL_P(hash);
|
||
beg = rb_reg_search0(pat, str, 0, 0, !str_replace);
|
||
if (beg < 0) {
|
||
if (bang) return Qnil; /* no match, no substitution */
|
||
return rb_str_dup(str);
|
||
... | ... | |
regs = RMATCH_REGS(match);
|
||
beg0 = BEG(0);
|
||
end0 = END(0);
|
||
if (iter || !NIL_P(hash)) {
|
||
if (!str_replace) {
|
||
if (iter) {
|
||
val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
|
||
}
|
||
... | ... | |
}
|
||
cp = RSTRING_PTR(str) + offset;
|
||
if (offset > RSTRING_LEN(str)) break;
|
||
beg = rb_reg_search(pat, str, offset, 0);
|
||
beg = rb_reg_search0(pat, str, offset, 0, !str_replace);
|
||
} while (beg >= 0);
|
||
if (RSTRING_LEN(str) > offset) {
|
||
rb_enc_str_buf_cat(dest, cp, RSTRING_LEN(str) - offset, str_enc);
|