0
@@ -3084,8 +3084,7 @@ get_pat(VALUE pat, int quote)
0
rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
0
- VALUE pat, repl, match, hash = Qnil;
0
- struct re_registers *regs;
0
+ VALUE pat, repl, hash = Qnil;
0
@@ -3109,15 +3108,13 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
0
if (rb_reg_search(pat, str, 0, 0) >= 0) {
0
int cr = ENC_CODERANGE(str);
0
- match = rb_backref_get();
0
- regs = RMATCH_REGS(match);
0
+ VALUE match = rb_backref_get();
0
+ struct re_registers *regs = RMATCH_REGS(match);
0
if (iter || !NIL_P(hash)) {
0
char *p = RSTRING_PTR(str); long len = RSTRING_LEN(str);
0
repl = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
0
@@ -3126,7 +3123,6 @@ rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
0
str_mod_check(str, p, len);
0
- if (iter) rb_backref_set(match);
0
repl = rb_reg_regsub(repl, str, regs, pat);
0
@@ -3217,7 +3213,8 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
0
VALUE pat, val, repl, match, dest, hash = Qnil;
0
struct re_registers *regs;
0
- long offset, blen, slen, len;
0
+ long offset, blen, slen, len, last;
0
@@ -3241,13 +3238,14 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
0
pat = get_pat(argv[0], 1);
0
beg = rb_reg_search(pat, str, 0, 0);
0
if (bang) return Qnil; /* no match, no substitution */
0
return rb_str_dup(str);
0
blen = RSTRING_LEN(str) + 30; /* len + margin */
0
dest = rb_str_buf_new(blen);
0
@@ -3259,9 +3257,10 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
0
match = rb_backref_get();
0
regs = RMATCH_REGS(match);
0
if (iter || !NIL_P(hash)) {
0
val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
0
@@ -3273,7 +3272,6 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
0
if (val == dest) { /* paranoid check [ruby-dev:24827] */
0
rb_raise(rb_eRuntimeError, "block should not cheat");
0
- if (iter) rb_backref_set(match);
0
val = rb_reg_regsub(repl, str, regs, pat);
0
@@ -3288,16 +3286,17 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
0
rb_str_buf_append(dest, val);
0
- if (BEG(0) == END(0)) {
0
* Always consume at least one character of the input string
0
* in order to prevent infinite loops.
0
- if (RSTRING_LEN(str) <= END(0)) break;
0
- len = rb_enc_mbclen(RSTRING_PTR(str)+END(0), RSTRING_END(str), str_enc);
0
- rb_enc_str_buf_cat(dest, RSTRING_PTR(str)+END(0), len, str_enc);
0
- offset = END(0) + len;
0
+ if (RSTRING_LEN(str) <= end0) break;
0
+ len = rb_enc_mbclen(RSTRING_PTR(str)+end0, RSTRING_END(str), str_enc);
0
+ rb_enc_str_buf_cat(dest, RSTRING_PTR(str)+end0, len, str_enc);
0
cp = RSTRING_PTR(str) + offset;
0
if (offset > RSTRING_LEN(str)) break;
0
@@ -3306,7 +3305,7 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
0
if (RSTRING_LEN(str) > offset) {
0
rb_enc_str_buf_cat(dest, cp, RSTRING_LEN(str) - offset, str_enc);
0
- rb_
backref_set(match);
0
+ rb_
reg_search(pat, str, last, 0);
0
rb_str_shared_replace(str, dest);
Comments
No one has commented yet.