Class: Parslet::Source::LineCache
- Inherits:
-
Object
- Object
- Parslet::Source::LineCache
- Defined in:
- lib/csscss/parslet_optimizations.rb
Instance Method Summary collapse
Instance Method Details
#scan_for_line_endings(start_pos, buf) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/csscss/parslet_optimizations.rb', line 55 def scan_for_line_endings(start_pos, buf) return unless buf buf = StringScanner.new(buf) return unless buf.exist?(/\n/) ## If we have already read part or all of buf, we already know about ## line ends in that portion. remove it and correct cur (search index) if @last_line_end && start_pos < @last_line_end # Let's not search the range from start_pos to last_line_end again. buf.pos = @last_line_end - start_pos end ## Scan the string for line endings; store the positions of all endings ## in @line_ends. while buf.skip_until(/\n/) @last_line_end = start_pos + buf.pos @line_ends << @last_line_end end end |