Method: Bychar::ReaderStrbuf#read_one_char
- Defined in:
- lib/impls/reader_strbuf.rb
#read_one_char ⇒ Object
Will transparently read one byte off the contained IO, maintaining the internal cache. If the cache has been depleted it will read a big chunk from the IO and cache it and then return the byte
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/impls/reader_strbuf.rb', line 17 def read_one_char if @pos_in_buf > @maximum_pos @buf = @io.read(DEFAULT_BUFFER_SIZE) return nil if @buf.nil? @maximum_pos = @buf.length - 1 @pos_in_buf = 0 end char_i = @pos_in_buf @pos_in_buf += 1 # For Ruby 1.8 calling Numeric#chr is faster than allocating a Range for String#slice @oneeight ? @buf[char_i].chr : @buf[char_i] end |