[前][次][番号順一覧][スレッド一覧]

ruby-changes:33367

From: nobu <ko1@a...>
Date: Thu, 27 Mar 2014 12:03:24 +0900 (JST)
Subject: [ruby-changes:33367] nobu:r45446 (trunk): string.c: invert flag

nobu	2014-03-27 12:03:19 +0900 (Thu, 27 Mar 2014)

  New Revision: 45446

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45446

  Log:
    string.c: invert flag
    
    * string.c (str_gsub): invert and rename `str_replace` flag as
      `need_backref`.

  Modified files:
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 45445)
+++ string.c	(revision 45446)
@@ -4021,7 +4021,7 @@ str_gsub(int argc, VALUE *argv, VALUE st https://github.com/ruby/ruby/blob/trunk/string.c#L4021
     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 st https://github.com/ruby/ruby/blob/trunk/string.c#L4042
     }
 
     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 st https://github.com/ruby/ruby/blob/trunk/string.c#L4066
 	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 st https://github.com/ruby/ruby/blob/trunk/string.c#L4106
 	}
 	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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]