diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-04-13 07:24:56 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-04-13 07:24:56 +0900 |
| commit | dd89a618b3d8ffce3f31f45d4e628cad34fd46b6 (patch) | |
| tree | 64f2d5166440bf8cf2110817b0a7d9b23fd67e71 | |
| parent | 9a9c842cb0fb14946008087ca22f66c783ee659f (diff) | |
| download | mruby-dd89a618b3d8ffce3f31f45d4e628cad34fd46b6.tar.gz mruby-dd89a618b3d8ffce3f31f45d4e628cad34fd46b6.zip | |
mruby-io: fix `IO#ungetbyte`; ref #5389
- remove `Integer#chr` (thus `mruby-sting-ext`) dependency
- fix the behavior when `c.is_a? String`
- fix the behavior when `c > 255`
| -rw-r--r-- | mrbgems/mruby-io/mrblib/io.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/mrbgems/mruby-io/mrblib/io.rb b/mrbgems/mruby-io/mrblib/io.rb index a60562846..9ce49e51a 100644 --- a/mrbgems/mruby-io/mrblib/io.rb +++ b/mrbgems/mruby-io/mrblib/io.rb @@ -184,9 +184,15 @@ class IO nil end - def ungetbyte(substr) - substr = substr.chr if substr.is_a? Integer - ungetc substr + def ungetbyte(c) + if c.is_a? String + c = c.getbyte(0) + else + c &= 0xff + end + s = " " + s.setbyte(0,c) + ungetc s end def read(length = nil, outbuf = "") |
