1 # regular string scanner works with bytes
2 # this one works with chars and provides #scan_next
4 class CharStringScanner
8 @s = StringScanner.new(*args)
11 def_delegators :@s, :scan_until, :skip_until, :string
13 # advance scanner to pos after the next match of pattern and return the match
14 def scan_next(pattern)
15 return unless @s.scan_until(pattern)
20 byte_to_str_pos @s.pos
24 @s.pos = str_to_byte_pos i
30 def byte_to_str_pos(pos)
31 @s.string.byteslice(0, pos).length
34 def str_to_byte_pos(pos)
35 @s.string.slice(0, pos).bytesize