class Puppet::Pops::Parser::Locator::Locator19
This implementation is for Ruby19 and Ruby20. It uses byteslice to get strings from byte based offsets. For Ruby20 this is faster than using the Stringscanner.charpos method (byteslice outperforms it, when strings are frozen).
Public Class Methods
_pcore_type()
click to toggle source
# File lib/puppet/pops/parser/locator.rb 318 def self._pcore_type 319 @type ||= Types::PObjectType.new('Puppet::AST::Locator', { 320 'attributes' => { 321 'string' => Types::PStringType::DEFAULT, 322 'file' => Types::PStringType::DEFAULT, 323 'line_index' => { 324 Types::KEY_TYPE => Types::POptionalType.new(Types::PArrayType.new(Types::PIntegerType::DEFAULT)), 325 Types::KEY_VALUE => nil 326 } 327 } 328 }) 329 end
Public Instance Methods
char_length(offset, end_offset)
click to toggle source
Returns the length measured in number of characters from the given start and end byte offset
# File lib/puppet/pops/parser/locator.rb 345 def char_length(offset, end_offset) 346 string.byteslice(offset, end_offset - offset).length 347 end
char_offset(byte_offset)
click to toggle source
Returns the character offset for a given byte offset Ruby 19 is multibyte but has no character position methods, must use byteslice
# File lib/puppet/pops/parser/locator.rb 340 def char_offset(byte_offset) 341 string.byteslice(0, byte_offset).length 342 end
extract_text(offset, length)
click to toggle source
Extracts the text from byte offset with given byte length @returns String - the extracted text
# File lib/puppet/pops/parser/locator.rb 351 def extract_text(offset, length) 352 string.byteslice(offset, length) 353 end
offset_on_line(offset)
click to toggle source
Returns the offset on line (first offset on a line is 0). Ruby 19 is multibyte but has no character position methods, must use byteslice
# File lib/puppet/pops/parser/locator.rb 333 def offset_on_line(offset) 334 line_offset = line_index[ line_for_offset(offset)-1 ] 335 @string.byteslice(line_offset, offset-line_offset).length 336 end