class
PoParser::Scanner
- PoParser::Scanner
- StringScanner
- Reference
- Object
Overview
Polyfill for 1.21 StringScanner methods missing on older Crystal versions
Defined in:
po_parser/scanner.crInstance Method Summary
- #beginning_of_line? : Bool
-
#check(pattern : Char) : String | Nil
Returns the value that
#scanwould return, without advancing the scan offset. - #current_char : Char
- #current_char? : Char | Nil
- #rewind(len : Int) : Nil
- #scan(len : Int) : String | Nil
-
#scan(pattern : Char) : String | Nil
Tries to match with pattern at the current position.
- #skip(len : Int) : Int32 | Nil
-
#skip(pattern : Char) : Int32 | Nil
Attempts to skip over the given pattern beginning with the scan offset.
Instance Method Detail
Returns the value that #scan would return, without advancing the scan
offset. The last match is still saved, however.
require "string_scanner"
s = StringScanner.new("this is a string")
s.offset = 5
s.check(/\w+/) # => "is"
s.check(/\w+/) # => "is"
Tries to match with pattern at the current position. If there's a match,
the scanner advances the scan offset, the last match is saved, and it
returns the matched string. Otherwise, the scanner returns nil.
require "string_scanner"
s = StringScanner.new("test string")
s.scan(/\w+/) # => "test"
s.scan(/\w+/) # => nil
s.scan(/\s\w/) # => " s"
s.scan('t') # => "t"
s.scan("ring") # => "ring"
s.scan(/.*/) # => ""
Attempts to skip over the given pattern beginning with the scan offset. In other words, the pattern is not anchored to the current scan offset.
If there's a match, the scanner advances the scan offset, the last match is
saved, and it returns the size of the skipped match. Otherwise it returns
nil and does not advance the offset.
This method is the same as #scan, but without returning the matched
string.