Class: Prism::CodeUnitsCache::UTF32Counter
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/prism/parse_result.rb |
Overview
Counter used for UTF-32, where one code unit equals one code point and
matches String#length. Also used as a best-effort fallback for any other
encoding that does not have a dedicated counter.
Class Method Summary
-
.new(source, encoding) ⇒ UTF32Counter
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) ⇒ UTF32Counter
: (String source, Encoding encoding) -> void
# File 'lib/prism/parse_result.rb', line 285
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 291
def count(byte_offset, byte_length) (@source.byteslice(byte_offset, byte_length) or raise).encode(@encoding, invalid: :replace, undef: :replace).length end