Class: BinaryPList::Parser::ObjectReaders::UTF16String

Inherits:
Base
  • Object
show all
Defined in:
lib/binary_plist/parser/object_readers/utf16_string.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from BinaryPList::Parser::ObjectReaders::Base

Class Method Details

.reads?(marker) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/binary_plist/parser/object_readers/utf16_string.rb', line 10

def self.reads?(marker)
  (0b0110_0000..0b0110_1111).include?(marker)
end

Instance Method Details

#read(marker) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/binary_plist/parser/object_readers/utf16_string.rb', line 14

def read(marker)
  raise UnsupportedMarkerError, marker unless self.class.reads?(marker)

  @marker = marker

  read_bytes(string_length * 2)
    .force_encoding("UTF-16BE")
    .encode("UTF-8")
end

#string_lengthObject



24
25
26
27
28
29
30
31
# File 'lib/binary_plist/parser/object_readers/utf16_string.rb', line 24

def string_length
  @string_length ||= if (@marker & 0xF) == 0xF
                       Int.new(nil, io, offset_table, trailer)
                          .read(read_byte)
                     else
                       @marker & 0xF
                     end
end