Module: PlatformosCheck::ParsingHelpers
- Included in:
- LiquidCheck
- Defined in:
- lib/platformos_check/parsing_helpers.rb
Instance Method Summary collapse
-
#outside_of_strings(markup) {|scanner.rest, scanner.charpos| ... } ⇒ Object
Yield each chunk outside of “…”, ‘…’.
Instance Method Details
#outside_of_strings(markup) {|scanner.rest, scanner.charpos| ... } ⇒ Object
Yield each chunk outside of “…”, ‘…’
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/platformos_check/parsing_helpers.rb', line 6 def outside_of_strings(markup) scanner = StringScanner.new(markup) while scanner.scan(/.*?("|')/m) chunk_start = scanner.pre_match.size yield scanner.matched[0..-2], chunk_start quote = scanner.matched[-1] == "'" ? "'" : "\"" # Skip to the end of the string # Check for empty string first, since follow regexp uses lookahead scanner.skip(/#{quote}/) || scanner.skip_until(/[^\\]#{quote}/) end yield scanner.rest, scanner.charpos if scanner.rest? end |