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

ruby-changes:18042

From: nobu <ko1@a...>
Date: Fri, 3 Dec 2010 07:08:55 +0900 (JST)
Subject: [ruby-changes:18042] Ruby:r30063 (trunk): * ext/stringio/stringio.c (strio_getline): round upto next char

nobu	2010-12-03 07:08:45 +0900 (Fri, 03 Dec 2010)

  New Revision: 30063

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

  Log:
    * ext/stringio/stringio.c (strio_getline): round upto next char
      boundary.  [ruby-dev:42674]

  Modified files:
    trunk/ChangeLog
    trunk/ext/stringio/stringio.c
    trunk/test/stringio/test_stringio.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30062)
+++ ChangeLog	(revision 30063)
@@ -1,3 +1,8 @@
+Fri Dec  3 07:08:42 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/stringio/stringio.c (strio_getline): round upto next char
+	  boundary.  [ruby-dev:42674]
+
 Fri Dec  3 06:52:46 2010  Tanaka Akira  <akr@f...>
 
 	* compile.c: parenthesize macro arguments.
Index: ext/stringio/stringio.c
===================================================================
--- ext/stringio/stringio.c	(revision 30062)
+++ ext/stringio/stringio.c	(revision 30063)
@@ -954,7 +954,7 @@
     e = s + RSTRING_LEN(ptr->string);
     s += ptr->pos;
     if (limit > 0 && s + limit < e) {
-	e = s + limit;
+	e = rb_enc_right_char_head(s, s + limit, e, rb_enc_get(ptr->string));
     }
     if (NIL_P(str)) {
 	str = strio_substr(ptr, ptr->pos, e - s);
Index: test/stringio/test_stringio.rb
===================================================================
--- test/stringio/test_stringio.rb	(revision 30062)
+++ test/stringio/test_stringio.rb	(revision 30063)
@@ -378,6 +378,12 @@
     assert_equal("a" * 10000 + "zz", f.gets("zz"))
     f = StringIO.new("a" * 10000 + "zz!")
     assert_equal("a" * 10000 + "zz!", f.gets("zzz"))
+
+    bug4112 = '[ruby-dev:42674]'
+    ["a".encode("utf-16be"), "\u3042"].each do |s|
+      assert_equal(s, StringIO.new(s).gets(1), bug4112)
+      assert_equal(s, StringIO.new(s).gets(nil, 1), bug4112)
+    end
   end
 
   def test_each

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

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