Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions ext/stringio/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1186,10 +1186,44 @@ strio_each_char(VALUE self)
* call-seq:
* each_codepoint {|codepoint| ... } -> self
*
* With a block given, calls the block with each remaining codepoint in the stream;
* see {Codepoint IO}[rdoc-ref:IO@Codepoint+IO].
*
* With no block given, returns an enumerator.
* With a block given, calls the block with each successive codepoint from self;
* sets the position to end-of-stream;
* returns +self+.
*
* Each codepoint is the integer value for a character; returns self:
*
* codepoints = []
* strio = StringIO.new('hello')
* strio.each_codepoint {|codepoint| codepoints.push(codepoint) }
* strio.eof? # => true
* codepoints # => [104, 101, 108, 108, 111]
* codepoints = []
* strio = StringIO.new('тест')
* strio.each_codepoint {|codepoint| codepoints.push(codepoint) }
* codepoints # => [1090, 1077, 1089, 1090]
* codepoints = []
* strio = StringIO.new('こんにちは')
* strio.each_codepoint {|codepoint| codepoints.push(codepoint) }
* codepoints # => [12371, 12435, 12395, 12385, 12399]
*
* Position in the stream matters:
*
* codepoints = []
* strio = StringIO.new('こんにちは')
* strio.getc # => "こ"
* strio.pos # => 3
* strio.each_codepoint {|codepoint| codepoints.push(codepoint) }
* codepoints # => [12435, 12395, 12385, 12399]
*
* When at end-of-stream, the block is not called:
*
* strio.eof? # => true
* strio.each_codepoint {|codepoint| fail 'Boo!' }
* strio.eof? # => true
*
* With no block given, returns a new {Enumerator}[https://docs.ruby-lang.org/en/master/Enumerator.html].
*
* Related: StringIO#each_byte, StringIO#each_char, StringIO#each_line.
*/
static VALUE
strio_each_codepoint(VALUE self)
Expand Down