Class: Prism::CodeUnitsCache::UTF16Counter
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/prism/parse_result.rb |
Class Method Summary
-
.new(source, encoding) ⇒ UTF16Counter
constructor
: (String source, Encoding encoding) -> void.
Instance Method Summary
-
#count(byte_offset, byte_length)
: (Integer byte_offset, Integer byte_length) -> Integer.
Constructor Details
.new(source, encoding) ⇒ UTF16Counter
: (String source, Encoding encoding) -> void
# File 'lib/prism/parse_result.rb', line 247
def initialize(source, encoding) @source = source @encoding = encoding end
Instance Method Details
#count(byte_offset, byte_length)
: (Integer byte_offset, Integer byte_length) -> Integer
# File 'lib/prism/parse_result.rb', line 253
def count(byte_offset, byte_length) (@source.byteslice(byte_offset, byte_length) or raise).encode(@encoding, invalid: :replace, undef: :replace).bytesize / 2 end