Sha256: 2ea30c5fadc2a940cc9511cc2ab092f2ec1e5455e02ff31125a8213bf89a6a0a

Contents?: true

Size: 932 Bytes

Versions: 2

Compression:

Stored size: 932 Bytes

Contents

# frozen_string_literal: true

require "binary_plist/parser/object_readers/base"
require "binary_plist/parser/object_readers/int"

module BinaryPList
  module Parser
    module ObjectReaders
      class UTF16String < Base
        def self.reads?(marker)
          (0b0110_0000..0b0110_1111).include?(marker)
        end

        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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
binary_plist-parser-0.1.1 lib/binary_plist/parser/object_readers/utf16_string.rb
binary_plist-parser-0.1.0 lib/binary_plist/parser/object_readers/utf16_string.rb