mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge branch 'io_getbyte' close #5389
This commit is contained in:
@@ -59,7 +59,7 @@ Add the line below to your build configuration.
|
||||
| IO#fileno, IO#to_i | o | |
|
||||
| IO#flush | o | |
|
||||
| IO#fsync | | |
|
||||
| IO#getbyte | | |
|
||||
| IO#getbyte | o | |
|
||||
| IO#getc | o | |
|
||||
| IO#gets | o | |
|
||||
| IO#internal_encoding | | |
|
||||
@@ -77,7 +77,7 @@ Add the line below to your build configuration.
|
||||
| IO#puts | o | |
|
||||
| IO#read | o | |
|
||||
| IO#read_nonblock | | |
|
||||
| IO#readbyte | | |
|
||||
| IO#readbyte | o | |
|
||||
| IO#readchar | o | |
|
||||
| IO#readline | o | |
|
||||
| IO#readlines | o | |
|
||||
@@ -93,7 +93,7 @@ Add the line below to your build configuration.
|
||||
| IO#sysseek | o | |
|
||||
| IO#syswrite | o | |
|
||||
| IO#to_io | | |
|
||||
| IO#ungetbyte | | |
|
||||
| IO#ungetbyte | o | |
|
||||
| IO#ungetc | o | |
|
||||
| IO#write | o | |
|
||||
| IO#write_nonblock | | |
|
||||
|
||||
@@ -184,6 +184,11 @@ class IO
|
||||
nil
|
||||
end
|
||||
|
||||
def ungetbyte(substr)
|
||||
substr = substr.chr if substr.is_a? Integer
|
||||
ungetc substr
|
||||
end
|
||||
|
||||
def read(length = nil, outbuf = "")
|
||||
unless length.nil?
|
||||
unless length.is_a? Integer
|
||||
@@ -290,12 +295,21 @@ class IO
|
||||
begin
|
||||
readchar
|
||||
rescue EOFError
|
||||
c = @buf[0]
|
||||
@buf[0,1]="" if c
|
||||
nil
|
||||
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
|
||||
def each(&block)
|
||||
return to_enum unless block
|
||||
|
||||
@@ -1476,6 +1476,9 @@ mrb_io_bufread(mrb_state *mrb, mrb_value self)
|
||||
mrb_int 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +105,15 @@ assert('IO#getc', '15.2.20.5.8') do
|
||||
io.close
|
||||
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#initialize_copy', '15.2.20.5.10') do
|
||||
#assert('IO#print', '15.2.20.5.11') do
|
||||
|
||||
Reference in New Issue
Block a user