Sha256: 87ef78c8174faabd457f71267b4fb9bd8da9dec30a699cf9c3f7252921f666c3

Contents?: true

Size: 930 Bytes

Versions: 2

Compression:

Stored size: 930 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 ASCIIString < Base
        def self.reads?(marker)
          (0b0101_0000..0b0101_1111).include?(marker)
        end

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

          @marker = marker

          read_bytes(string_length)
            .force_encoding("ASCII-8BIT")
            .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/ascii_string.rb
binary_plist-parser-0.1.0 lib/binary_plist/parser/object_readers/ascii_string.rb