summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-27 03:03:19 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-27 03:03:19 +0000
commit949f1160d6120d66b87729f43b1d487699685760 (patch)
tree84f1ac052eb7981ac02c9361d465399bfa6e62fd
parentacc3cf5f302d8db60db7d8a5e9790d29c5c6c553 (diff)
string.c: invert flag
* string.c (str_gsub): invert and rename `str_replace` flag as `need_backref`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--string.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/string.c b/string.c
index 936cc18ac4..c7150a8c3e 100644
--- a/string.c
+++ b/string.c
@@ -4021,7 +4021,7 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
int iter = 0;
char *sp, *cp;
int tainted = 0;
- int str_replace;
+ int need_backref;
rb_encoding *str_enc;
switch (argc) {
@@ -4042,8 +4042,8 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
}
pat = get_pat(argv[0], 1);
- str_replace = !iter && NIL_P(hash);
- beg = rb_reg_search0(pat, str, 0, 0, !str_replace);
+ need_backref = iter || !NIL_P(hash);
+ beg = rb_reg_search0(pat, str, 0, 0, need_backref);
if (beg < 0) {
if (bang) return Qnil; /* no match, no substitution */
return rb_str_dup(str);
@@ -4066,7 +4066,7 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
regs = RMATCH_REGS(match);
beg0 = BEG(0);
end0 = END(0);
- if (!str_replace) {
+ if (need_backref) {
if (iter) {
val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
}
@@ -4106,7 +4106,7 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
}
cp = RSTRING_PTR(str) + offset;
if (offset > RSTRING_LEN(str)) break;
- beg = rb_reg_search0(pat, str, offset, 0, !str_replace);
+ beg = rb_reg_search0(pat, str, offset, 0, need_backref);
} while (beg >= 0);
if (RSTRING_LEN(str) > offset) {
rb_enc_str_buf_cat(dest, cp, RSTRING_LEN(str) - offset, str_enc);