each_char()
public
Calls the given block once for each character
in ios, passing the character as an argument. The stream must be
opened for reading or an IOError will
be raised. Multibyte characters are dealt with according to $KCODE.
f = File.new("testfile")
f.each_char {|c| print c, ' ' }
Show source
/*
* call-seq:
* ios.each_char {|c| block } => ios
*
* Calls the given block once for each character in <em>ios</em>,
* passing the character as an argument. The stream must be opened for
* reading or an <code>IOError</code> will be raised. Multibyte
* characters are dealt with according to $KCODE.
*
* f = File.new("testfile")
* f.each_char {|c| print c, ' ' } #=> #<File:testfile>
*/
static VALUE
rb_io_each_char(io)
VALUE io;
{
VALUE ch;
RETURN_ENUMERATOR(io, 0, 0);
while (!NIL_P(ch = rb_io_getc(io))) {
unsigned char c;
int n;
VALUE str;
c= FIX2INT(ch);
n = mbclen(c);
str = rb_tainted_str_new((const char *)&c, 1);
while (--n > 0) {
if (NIL_P(ch = rb_io_getc(io))) {
rb_yield(str);
return io;
}
c = FIX2INT(ch);
rb_str_cat(str, (const char *)&c, 1);
}
rb_yield(str);
}
return io;
}