Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 34 additions & 0 deletions doc/stringio/getc.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Reads and returns the next character (or byte; see below) from the stream:

strio = StringIO.new('foo')
strio.getc # => "f"
strio.getc # => "o"
strio.getc # => "o"

Returns +nil+ if at end-of-stream:

strio.eof? # => true
strio.getc # => nil

Returns characters, not bytes:

strio = StringIO.new('тест')
strio.getc # => "т"
strio.getc # => "е"

strio = StringIO.new('こんにちは')
strio.getc # => "こ"
strio.getc # => "ん"

In each of the examples above, the stream is positioned at the beginning of a character;
in other cases that need not be true:

strio = StringIO.new('こんにちは') # Five 3-byte characters.
strio.pos = 3 # => 3 # At beginning of second character; returns character.
strio.getc # => "ん"
strio.pos = 4 # => 4 # At second byte of second character; returns byte.
strio.getc # => "\x82"
strio.pos = 5 # => 5 # At third byte of second character; returns byte.
strio.getc # => "\x93"

Related: StringIO.getbyte.
6 changes: 3 additions & 3 deletions ext/stringio/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,10 +956,10 @@ strio_each_byte(VALUE self)

/*
* call-seq:
* getc -> character or nil
* getc -> character, byte, or nil
*
* :include: stringio/getc.rdoc
*
* Reads and returns the next character from the stream;
* see {Character IO}[rdoc-ref:IO@Character+IO].
*/
static VALUE
strio_getc(VALUE self)
Expand Down
Loading