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

ruby-changes:42993

From: nobu <ko1@a...>
Date: Thu, 19 May 2016 11:37:44 +0900 (JST)
Subject: [ruby-changes:42993] nobu:r55067 (trunk): re.c: match? should return nil if no match

nobu	2016-05-19 11:37:38 +0900 (Thu, 19 May 2016)

  New Revision: 55067

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55067

  Log:
    re.c: match? should return nil if no match
    
    * re.c (rb_reg_match_m_p): should return nil if no match, as the
      document says.  [Feature #8110]

  Modified files:
    trunk/ChangeLog
    trunk/re.c
    trunk/test/ruby/test_regexp.rb
Index: test/ruby/test_regexp.rb
===================================================================
--- test/ruby/test_regexp.rb	(revision 55066)
+++ test/ruby/test_regexp.rb	(revision 55067)
@@ -528,13 +528,13 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L528
 
   def test_match_p
     /backref/ =~ 'backref'
-    assert_nil(//.match?(nil))
+    assert_equal(false, //.match?(nil))
     assert_equal(true, /.../.match?(:abc))
     assert_raise(TypeError) { /.../.match?(Object.new) }
     assert_equal(true, /../.match?('abc', 1))
     assert_equal(true, /../.match?('abc', -2))
-    assert_nil(/../.match?("abc", -4))
-    assert_nil(/../.match?("abc", 4))
+    assert_equal(false, /../.match?("abc", -4))
+    assert_equal(false, /../.match?("abc", 4))
     assert_equal(true, /../n.match?("\u3042" + '\x', 1))
     assert_equal('backref', $&)
   end
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55066)
+++ ChangeLog	(revision 55067)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu May 19 11:37:36 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* re.c (rb_reg_match_m_p): should return nil if no match, as the
+	  document says.  [Feature #8110]
+
 Thu May 19 00:17:01 2016  NARUSE, Yui  <naruse@r...>
 
 	* re.c (reg_names_iter): specify capacify
Index: re.c
===================================================================
--- re.c	(revision 55066)
+++ re.c	(revision 55067)
@@ -3230,7 +3230,7 @@ rb_reg_match_m_p(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/re.c#L3230
     int tmpreg;
 
     rb_scan_args(argc, argv, "11", &str, &initpos);
-    if (NIL_P(str)) return Qnil;
+    if (NIL_P(str)) return Qfalse;
     str = SYMBOL_P(str) ? rb_sym2str(str) : rb_str_to_str(str);
     if (argc == 2) {
 	pos = NUM2LONG(initpos);
@@ -3238,14 +3238,14 @@ rb_reg_match_m_p(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/re.c#L3238
 	if (pos < 0) {
 	    pos += NUM2LONG(rb_str_length(str));
 	    if (pos == 0) goto run;
-	    if (pos < 0) return Qnil;
+	    if (pos < 0) return Qfalse;
 
 	}
 	pos = rb_str_offset(str, pos);
     }
 run:
     if (pos >= RSTRING_LEN(str)) {
-	return Qnil;
+	return Qfalse;
     }
     reg = rb_reg_prepare_re0(re, str, err);
     tmpreg = reg != RREGEXP_PTR(re);

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

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