class HexaPDF::Font::CMap

def read_codes(string)

An error is raised if the string contains invalid bytes.

Parses the string and returns all character codes.
def read_codes(string)
  codes = []
  bytes = string.each_byte
  loop do
    byte = bytes.next
    code = 0
    found = @codespace_ranges.any? do |first_byte_range, rest_ranges|
      next unless first_byte_range.cover?(byte)
      code = (code << 8) + byte
      valid = rest_ranges.all? do |range|
        begin
          byte = bytes.next
        rescue StopIteration
          raise HexaPDF::Error, "Missing bytes while reading codes via CMap"
        end
        code = (code << 8) + byte
        range.cover?(byte)
      end
      codes << code if valid
    end
    unless found
      raise HexaPDF::Error, "Invalid byte while reading codes via CMap: #{byte}"
    end
  end
  codes
end