1 class ScanError < StandardError; end
4 Id = "bite me $Id".freeze
5 Version = "1.0.0".freeze
8 attr_reader :match, :string
18 pos == 0 or string[pos-1..pos-1] == "\n"
20 alias :beginning_of_line? :bol?
23 _scan pattern, false, true, true
26 def check_until pattern
27 _scan pattern, false, true, false
31 warn "StringScanner#clear is obsolete; use #terminate instead"
39 alias :<< :concat # TODO: reverse
42 warn "StringScanner#empty? is obsolete; use #eos? instead?"
49 self.pos >= self.string.size
53 _scan pattern, false, false, false
61 warn "StringScanner#getbyte is obsolete; use #get_byte instead"
69 def initialize string, dup = false
75 if defined? @string then
76 rest = string.size > 5 ? string[pos..pos+4] + "..." : string
78 "#<StringScanner fin>"
80 prev = string[0...pos].inspect
81 "#<StringScanner #{pos}/#{string.size} #{prev} @ #{rest.inspect}>"
83 "#<StringScanner #{pos}/#{string.size} @ #{rest.inspect}>"
85 r.taint if self.string.tainted?
88 "#<StringScanner (uninitialized)>"
93 _scan pattern, false, false, true
97 match.to_s if matched?
105 match.to_s.size if matched?
109 warn "StringScanner#matchedsize is obsolete; use #matched_size instead"
114 match.post_match if matched?
118 string[0, match.begin(0)] if matched?
122 @prev_pos = self.pos = 0
140 warn "StringScanner#restsize is obsolete; use #rest_size instead"
145 _scan pattern, true, true, true
148 def scan_until pattern
149 _scan pattern, true, true, false
152 def scan_full pattern, succptr, getstr
153 _scan pattern, succptr, getstr, true
156 def search_full pattern, succptr, getstr
157 _scan pattern, succptr, getstr, false
160 def self.must_C_version
165 _scan pattern, true, false, true
168 def skip_until pattern
169 _scan pattern, true, false, false
179 self.pos = string.size
184 raise ScanError if @match.nil?
192 raise ArgumentError if len < 0
193 return "" if len.zero?
194 return string.substring(pos, len)
198 warn "StringScanner#peep is obsolete; use #peek instead"
202 def _scan pattern, succptr, getstr, headonly
207 return nil if (string.size - pos) < 0 # TODO: make more elegant
209 @match = if headonly then
210 pattern.match_start(string, pos)
212 pattern.search_region(string, pos, string.size, true)
215 return nil if match.nil?
217 m = string[pos...match.end(0)]
233 raise ArgumentError unless instance_variable_defined?(:@string)