Class: Firebug::StringIOReader
- Inherits:
-
StringIO
- Object
- StringIO
- Firebug::StringIOReader
- Defined in:
- lib/firebug/string_io_reader.rb
Overview
Class for reading a string
Instance Method Summary collapse
-
#read_until(char, include: true) ⇒ String?
Reads data from the buffer until
charis found.
Instance Method Details
#read_until(char, include: true) ⇒ String?
Reads data from the buffer until char is found.
11 12 13 14 15 16 17 18 |
# File 'lib/firebug/string_io_reader.rb', line 11 def read_until(char, include: true) # because UTF-8 is a variable-length encoding and +String#index+ returns the character index, not the byte index, # we use +String#b+ to convert the string to ASCII-8BIT. This forces Ruby to treat each byte as a single # character. This is needed because we have to know how many bytes from +pos+ the +char+ is. if (idx = string.b.index(char, pos)) # rubocop:disable Style/GuardClause read(idx - pos + (include ? 1 : 0)) end end |