Class: HTML5::ContentAttrParser

Inherits:
Object
  • Object
show all
Defined in:
lib/html5/inputstream.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ContentAttrParser

Returns a new instance of ContentAttrParser.



689
690
691
# File 'lib/html5/inputstream.rb', line 689

def initialize(data)
  @data = data
end

Instance Method Details

#parseObject



693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
# File 'lib/html5/inputstream.rb', line 693

def parse
  begin
    #Skip to the first ";"
    @data.position = 0
    @data.jump_to(';')
    @data.position += 1
    @data.skip
    #Check if the attr name is charset 
    #otherwise return
    @data.jump_to('charset')
    @data.position += 1
    @data.skip
    unless @data.current_byte == '='
      #If there is no = sign keep looking for attrs
      return nil
    end
    @data.position += 1
    @data.skip
    #Look for an encoding between matching quote marks
    if ['"', "'"].include?(@data.current_byte)
      quote_mark = @data.current_byte
      @data.position += 1
      old_position = @data.position
      @data.jump_to(quote_mark)
      return @data[old_position ... @data.position]
    else
      #Unquoted value
      old_position = @data.position
      begin
        @data.find_next(SPACE_CHARACTERS)
        return @data[old_position ... @data.position]
      rescue EOF
        #Return the whole remaining value
        return @data[old_position .. -1]
      end
    end
  rescue EOF
    return nil
  end
end