Merge branch 'io_getbyte' close #5389

parents 44d5e214 5cac9c84
...@@ -59,7 +59,7 @@ Add the line below to your build configuration. ...@@ -59,7 +59,7 @@ Add the line below to your build configuration.
| IO#fileno, IO#to_i | o | | | IO#fileno, IO#to_i | o | |
| IO#flush | o | | | IO#flush | o | |
| IO#fsync | | | | IO#fsync | | |
| IO#getbyte | | | | IO#getbyte | o | |
| IO#getc | o | | | IO#getc | o | |
| IO#gets | o | | | IO#gets | o | |
| IO#internal_encoding | | | | IO#internal_encoding | | |
...@@ -77,7 +77,7 @@ Add the line below to your build configuration. ...@@ -77,7 +77,7 @@ Add the line below to your build configuration.
| IO#puts | o | | | IO#puts | o | |
| IO#read | o | | | IO#read | o | |
| IO#read_nonblock | | | | IO#read_nonblock | | |
| IO#readbyte | | | | IO#readbyte | o | |
| IO#readchar | o | | | IO#readchar | o | |
| IO#readline | o | | | IO#readline | o | |
| IO#readlines | o | | | IO#readlines | o | |
...@@ -93,7 +93,7 @@ Add the line below to your build configuration. ...@@ -93,7 +93,7 @@ Add the line below to your build configuration.
| IO#sysseek | o | | | IO#sysseek | o | |
| IO#syswrite | o | | | IO#syswrite | o | |
| IO#to_io | | | | IO#to_io | | |
| IO#ungetbyte | | | | IO#ungetbyte | o | |
| IO#ungetc | o | | | IO#ungetc | o | |
| IO#write | o | | | IO#write | o | |
| IO#write_nonblock | | | | IO#write_nonblock | | |
......
...@@ -184,6 +184,11 @@ class IO ...@@ -184,6 +184,11 @@ class IO
nil nil
end end
def ungetbyte(substr)
substr = substr.chr if substr.is_a? Integer
ungetc substr
end
def read(length = nil, outbuf = "") def read(length = nil, outbuf = "")
unless length.nil? unless length.nil?
unless length.is_a? Integer unless length.is_a? Integer
...@@ -290,12 +295,21 @@ class IO ...@@ -290,12 +295,21 @@ class IO
begin begin
readchar readchar
rescue EOFError rescue EOFError
c = @buf[0]
@buf[0,1]="" if c
nil nil
end end
end end
def readbyte
_read_buf
IO._bufread(@buf, 1).getbyte(0)
end
def getbyte
readbyte
rescue EOFError
nil
end
# 15.2.20.5.3 # 15.2.20.5.3
def each(&block) def each(&block)
return to_enum unless block return to_enum unless block
......
...@@ -1476,6 +1476,9 @@ mrb_io_bufread(mrb_state *mrb, mrb_value self) ...@@ -1476,6 +1476,9 @@ mrb_io_bufread(mrb_state *mrb, mrb_value self)
mrb_int len; mrb_int len;
mrb_get_args(mrb, "Si", &str, &len); mrb_get_args(mrb, "Si", &str, &len);
mrb_assert(RSTRING_LEN(str) > 0);
mrb_assert(RSTRING_PTR(str) != NULL);
mrb_str_modify(mrb, RSTRING(str));
return io_bufread(mrb, str, len); return io_bufread(mrb, str, len);
} }
......
...@@ -105,6 +105,15 @@ assert('IO#getc', '15.2.20.5.8') do ...@@ -105,6 +105,15 @@ assert('IO#getc', '15.2.20.5.8') do
io.close io.close
end end
assert('IO#getbyte') do
io = IO.new(IO.sysopen($mrbtest_io_rfname))
$mrbtest_io_msg.split("").each do |ch|
assert_equal ch.getbyte(0), io.getbyte
end
assert_equal nil, io.getbyte
io.close
end
#assert('IO#gets', '15.2.20.5.9') do #assert('IO#gets', '15.2.20.5.9') do
#assert('IO#initialize_copy', '15.2.20.5.10') do #assert('IO#initialize_copy', '15.2.20.5.10') do
#assert('IO#print', '15.2.20.5.11') do #assert('IO#print', '15.2.20.5.11') do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment