def charset_from_meta(string)

      position = 0
      attribute_list = {}
      got_pragma = false
      need_pragma = nil
      charset = nil
      length = string.length

      while position < length

        attribute, position_increment = attribute(string[position, length])
        
        position += position_increment.to_i

        if attribute == nil

          break

        elsif attribute_list[attribute[:attribute_name]]

          # Do nothing
        
        else

          # found a new attribute. Add it to the list
          attribute_list[attribute[:attribute_name]] = attribute[:attribute_value]

          if attribute[:attribute_name] == 'http-equiv'

            got_pragma = true

          elsif attribute[:attribute_name] == 'content'

            content_charset = charset_from_meta_content(attribute[:attribute_value])

            if content_charset && charset == nil
              charset = content_charset
              need_pragma = true
            end

          elsif attribute[:attribute_name] == 'charset'

            charset = attribute[:attribute_value]
            need_pragma = false

          end

        end

      end

      if need_pragma == nil || (need_pragma == true && got_pragma == false)
        [nil, position]
      else
        [charset, position]
      end
      
    end
def charset_from_meta(string)

      position = 0
      attribute_list = {}
      got_pragma = false
      need_pragma = nil
      charset = nil
      length = string.length

      while position < length

        attribute, position_increment = attribute(string[position, length])
        
        position += position_increment.to_i

        if attribute == nil

          break

        elsif attribute_list[attribute[:attribute_name]]

          # Do nothing
        
        else

          # found a new attribute. Add it to the list
          attribute_list[attribute[:attribute_name]] = attribute[:attribute_value]

          if attribute[:attribute_name] == 'http-equiv'

            got_pragma = true

          elsif attribute[:attribute_name] == 'content'

            content_charset = charset_from_meta_content(attribute[:attribute_value])

            if content_charset && charset == nil
              charset = content_charset
              need_pragma = true
            end

          elsif attribute[:attribute_name] == 'charset'

            charset = attribute[:attribute_value]
            need_pragma = false

          end

        end

      end

      if need_pragma == nil || (need_pragma == true && got_pragma == false)
        [nil, position]
      else
        [charset, position]
      end
      
    end
Given a string which starts with the space or slash following a `<meta`,
 look for a charset and returns it along with the position of the next
 character following the closing `>` character