def eat_this(line)
      @rest = line + @rest
      things_read = 0
      until @rest.empty?
        case self.state
        when :inside_comment
          if @m = CommentEnd.match(@rest)
            debug_state 'Comment End'
            # Workaround for https://bugs.ruby-lang.org/issues/9277 and another bug in 1.9.2 where even a
            # single dash in a comment will cause REXML to error.
            @already << @m.pre_match.gsub(/-(?![^\-])/, '- ') << @m.to_s
            @rest = @m.post_match
            self.state = :inside_element
          else
            @already << @rest.gsub(/-(?![^\-])/, '- ') # Workaround for https://bugs.ruby-lang.org/issues/9277
            @rest = ""
            self.state = :inside_comment
          end
        when :inside_element
          if @m = CommentStart.match(@rest)
            debug_state 'Comment'
            things_read += 1
            @already << @m.pre_match << @m.to_s
            @rest = @m.post_match
            self.state = :inside_comment
          elsif @m = Tag.match(@rest)
            debug_state 'Tag'
            things_read += 1
            self.state = :inside_element
            handle_tag
          elsif @m = CData.match(@rest)
            debug_state 'CDATA'
            @already << @m.pre_match
            close_script_style if script_style?
            @already << @m.to_s
            @rest = @m.post_match
            self.state = :inside_cdata
          elsif @m = PartialTag.match(@rest)
            debug_state 'PartialTag'
            @already << @m.pre_match
            @rest = @m.post_match
            @partial_tag = @m.to_s
            self.state = :inside_tag
          elsif @m = EverythingElse.match(@rest)
            debug_state 'EverythingElse'
            @already << @m.pre_match << @m.to_s
            @rest = @m.post_match
            self.state = :inside_element
          else
            error "Malformed HTML: not complete: #{@rest.inspect}"
          end
        when :inside_tag
          if @m = /^[^>]*>/.match(@rest)
            @partial_tag << @m.to_s
            @rest = @partial_tag + @m.post_match
            @partial_tag = nil
            self.state = :inside_element
            if @m = Tag.match(@rest)
              things_read += 1
              handle_tag
            end
          else
            @partial_tag << @rest
            @rest = ""
            self.state = :inside_tag
          end
        when :inside_cdata
          if @m = CDataEnd.match(@rest)
            self.state = :inside_element
            @already << @m.pre_match << @m.to_s
            @rest = @m.post_match
            start_script_style if script_style?
          else
            @already << @rest
            @rest = ""
            self.state = :inside_cdata
          end
        else
          raise "Bug bug: state = #{self.state.inspect}"
        end

        break if is_finished? && things_read > 0
      end
    end
def eat_this(line)
      @rest = line + @rest
      things_read = 0
      until @rest.empty?
        case self.state
        when :inside_comment
          if @m = CommentEnd.match(@rest)
            debug_state 'Comment End'
            # Workaround for https://bugs.ruby-lang.org/issues/9277 and another bug in 1.9.2 where even a
            # single dash in a comment will cause REXML to error.
            @already << @m.pre_match.gsub(/-(?![^\-])/, '- ') << @m.to_s
            @rest = @m.post_match
            self.state = :inside_element
          else
            @already << @rest.gsub(/-(?![^\-])/, '- ') # Workaround for https://bugs.ruby-lang.org/issues/9277
            @rest = ""
            self.state = :inside_comment
          end
        when :inside_element
          if @m = CommentStart.match(@rest)
            debug_state 'Comment'
            things_read += 1
            @already << @m.pre_match << @m.to_s
            @rest = @m.post_match
            self.state = :inside_comment
          elsif @m = Tag.match(@rest)
            debug_state 'Tag'
            things_read += 1
            self.state = :inside_element
            handle_tag
          elsif @m = CData.match(@rest)
            debug_state 'CDATA'
            @already << @m.pre_match
            close_script_style if script_style?
            @already << @m.to_s
            @rest = @m.post_match
            self.state = :inside_cdata
          elsif @m = PartialTag.match(@rest)
            debug_state 'PartialTag'
            @already << @m.pre_match
            @rest = @m.post_match
            @partial_tag = @m.to_s
            self.state = :inside_tag
          elsif @m = EverythingElse.match(@rest)
            debug_state 'EverythingElse'
            @already << @m.pre_match << @m.to_s
            @rest = @m.post_match
            self.state = :inside_element
          else
            error "Malformed HTML: not complete: #{@rest.inspect}"
          end
        when :inside_tag
          if @m = /^[^>]*>/.match(@rest)
            @partial_tag << @m.to_s
            @rest = @partial_tag + @m.post_match
            @partial_tag = nil
            self.state = :inside_element
            if @m = Tag.match(@rest)
              things_read += 1
              handle_tag
            end
          else
            @partial_tag << @rest
            @rest = ""
            self.state = :inside_tag
          end
        when :inside_cdata
          if @m = CDataEnd.match(@rest)
            self.state = :inside_element
            @already << @m.pre_match << @m.to_s
            @rest = @m.post_match
            start_script_style if script_style?
          else
            @already << @rest
            @rest = ""
            self.state = :inside_cdata
          end
        else
          raise "Bug bug: state = #{self.state.inspect}"
        end

        break if is_finished? && things_read > 0
      end
    end
= :inside_element, :inside_tag, :inside_comment, :inside_cdata