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

ruby-changes:26421

From: usa <ko1@a...>
Date: Wed, 19 Dec 2012 21:25:07 +0900 (JST)
Subject: [ruby-changes:26421] usa:r38472 (ruby_1_9_3): merge revision(s) 37851: [Backport #7438]

usa	2012-12-19 21:24:54 +0900 (Wed, 19 Dec 2012)

  New Revision: 38472

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

  Log:
    merge revision(s) 37851: [Backport #7438]
    
    * io.c (argf_each_codepoint): add missing ARGF#codepoints [Bug #7438]

  Modified directories:
    branches/ruby_1_9_3/
  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/io.c
    branches/ruby_1_9_3/test/ruby/test_argf.rb
    branches/ruby_1_9_3/version.h

Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 38471)
+++ ruby_1_9_3/ChangeLog	(revision 38472)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ChangeLog#L1
+Wed Dec 19 21:24:40 2012  NARUSE, Yui  <naruse@r...>
+
+	* io.c (argf_each_codepoint): add missing ARGF#codepoints [Bug #7438]
+
 Wed Dec 19 21:20:23 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* file.c (file_expand_path): use wcscasecmp().
Index: ruby_1_9_3/io.c
===================================================================
--- ruby_1_9_3/io.c	(revision 38471)
+++ ruby_1_9_3/io.c	(revision 38472)
@@ -10565,6 +10565,36 @@ argf_each_char(VALUE argf) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/io.c#L10565
 
 /*
  *  call-seq:
+ *     ARGF.codepoints      {|codepoint| block }  -> ARGF
+ *     ARGF.codepoints                       -> an_enumerator
+ *
+ *     ARGF.each_codepoint  {|codepoint| block }  -> ARGF
+ *     ARGF.each_codepoint                   -> an_enumerator
+ *
+ *  Iterates over each codepoint of each file in +ARGF+.
+ *
+ *  This method allows you to treat the files supplied on the command line as
+ *  a single file consisting of the concatenation of each named file. After
+ *  the last codepoint of the first file has been returned, the first
+ *  codepoint of the second file is returned. The +ARGF.filename+ method can
+ *  be used to determine the name of the file in which the current codepoint
+ *  appears.
+ *
+ *  If no block is given, an enumerator is returned instead.
+ */
+static VALUE
+argf_each_codepoint(VALUE argf)
+{
+    RETURN_ENUMERATOR(argf, 0, 0);
+    for (;;) {
+	if (!next_argv()) return argf;
+	rb_block_call(ARGF.current_file, rb_intern("each_codepoint"), 0, 0, 0, 0);
+	ARGF.next_p = 1;
+    }
+}
+
+/*
+ *  call-seq:
  *     ARGF.filename  -> String
  *     ARGF.path      -> String
  *
@@ -11291,9 +11321,11 @@ Init_IO(void) https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/io.c#L11321
     rb_define_method(rb_cARGF, "each_line",  argf_each_line, -1);
     rb_define_method(rb_cARGF, "each_byte",  argf_each_byte, 0);
     rb_define_method(rb_cARGF, "each_char",  argf_each_char, 0);
+    rb_define_method(rb_cARGF, "each_codepoint",  argf_each_codepoint, 0);
     rb_define_method(rb_cARGF, "lines", argf_each_line, -1);
     rb_define_method(rb_cARGF, "bytes", argf_each_byte, 0);
     rb_define_method(rb_cARGF, "chars", argf_each_char, 0);
+    rb_define_method(rb_cARGF, "codepoints", argf_each_codepoint, 0);
 
     rb_define_method(rb_cARGF, "read",  argf_read, -1);
     rb_define_method(rb_cARGF, "readpartial",  argf_readpartial, -1);
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 38471)
+++ ruby_1_9_3/version.h	(revision 38472)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/version.h#L1
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 345
+#define RUBY_PATCHLEVEL 346
 
 #define RUBY_RELEASE_DATE "2012-12-19"
 #define RUBY_RELEASE_YEAR 2012
Index: ruby_1_9_3/test/ruby/test_argf.rb
===================================================================
--- ruby_1_9_3/test/ruby/test_argf.rb	(revision 38471)
+++ ruby_1_9_3/test/ruby/test_argf.rb	(revision 38472)
@@ -756,4 +756,28 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/test/ruby/test_argf.rb#L756
     bug5952 = '[ruby-dev:45160]'
     assert_ruby_status(["-e", "2.times {STDIN.tty?; readlines}"], "", bug5952)
   end
+
+  def test_bytes
+    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+      print Marshal.dump(ARGF.bytes.to_a)
+    SRC
+      assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read))
+    end
+  end
+
+  def test_chars
+    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+      print Marshal.dump(ARGF.chars.to_a)
+    SRC
+      assert_equal(["1", "\n", "2", "\n", "3", "\n", "4", "\n", "5", "\n", "6", "\n"], Marshal.load(f.read))
+    end
+  end
+
+  def test_codepoints
+    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+      print Marshal.dump(ARGF.codepoints.to_a)
+    SRC
+      assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read))
+    end
+  end
 end

Property changes on: ruby_1_9_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r37851


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

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