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

ruby-changes:30031

From: naruse <ko1@a...>
Date: Sat, 20 Jul 2013 18:10:29 +0900 (JST)
Subject: [ruby-changes:30031] naruse:r42082 (trunk): * string.c (rb_str_succ): add missing case NEIGHBOR_WRAPPED.

naruse	2013-07-20 18:10:12 +0900 (Sat, 20 Jul 2013)

  New Revision: 42082

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

  Log:
    * string.c (rb_str_succ): add missing case NEIGHBOR_WRAPPED.
      r42078 caused buggy behavior like "\xFF".b -> "\x01\xFF".b

  Modified files:
    trunk/ChangeLog
    trunk/string.c
    trunk/test/ruby/test_m17n_comb.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42081)
+++ ChangeLog	(revision 42082)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jul 20 17:46:03 2013  NARUSE, Yui  <naruse@r...>
+
+	* string.c (rb_str_succ): add missing case NEIGHBOR_WRAPPED.
+	  r42078 caused buggy behavior like "\xFF".b -> "\x01\xFF".b
+
 Sat Jul 20 15:22:38 2013  Koichi Sasada  <ko1@a...>
 
 	* array.c (rb_ary_resize): use simple memcpy because there are no new
Index: string.c
===================================================================
--- string.c	(revision 42081)
+++ string.c	(revision 42082)
@@ -3117,9 +3117,16 @@ rb_str_succ(VALUE orig) https://github.com/ruby/ruby/blob/trunk/string.c#L3117
 	    l = ONIGENC_MBCLEN_CHARFOUND_LEN(l);
 	    MEMCPY(tmp, s, char, l);
 	    neighbor = enc_succ_char(tmp, l, enc);
-	    if (neighbor == NEIGHBOR_FOUND) {
+	    switch (neighbor) {
+	      case NEIGHBOR_FOUND:
 		MEMCPY(s, tmp, char, l);
                 return str;
+		break;
+	      case NEIGHBOR_WRAPPED:
+		MEMCPY(s, tmp, char, l);
+		break;
+	      case NEIGHBOR_NOT_CHAR:
+		break;
 	    }
             if (rb_enc_precise_mbclen(s, s+l, enc) != l) {
                 /* wrapped to \0...\0.  search next valid char. */
Index: test/ruby/test_m17n_comb.rb
===================================================================
--- test/ruby/test_m17n_comb.rb	(revision 42081)
+++ test/ruby/test_m17n_comb.rb	(revision 42082)
@@ -1340,6 +1340,11 @@ class TestM17NComb < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_m17n_comb.rb#L1340
     end
   end
 
+  def test_str_succ2
+    assert_equal("\x01\x00".force_encoding("US-ASCII"), "\x7f".force_encoding("US-ASCII").succ)
+    assert_equal("\x01\x00".b, "\xff".b.succ)
+  end
+
   def test_str_hash
     combination(STRINGS, STRINGS) {|s1, s2|
       if s1.eql?(s2)

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

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