summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-19 12:24:54 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-19 12:24:54 +0000
commitc3fcb13ce03a63d333ada192f7c1b59bb26f66d8 (patch)
tree349c72cca7cb71c749c5679b6c332957a35959c9 /io.c
parent94d2a3513971d4ceb3b52346169afcb3cc7ad5b9 (diff)
merge revision(s) 37851: [Backport #7438]
* io.c (argf_each_codepoint): add missing ARGF#codepoints [Bug #7438] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@38472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/io.c b/io.c
index 36eb39d3d6..82a24f06a8 100644
--- a/io.c
+++ b/io.c
@@ -10565,6 +10565,36 @@ argf_each_char(VALUE argf)
/*
* 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)
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);