module HTTP::Accept::QuotedString

Public Class Methods

quote(value, force = false) click to toggle source

Quote a string if required. Doesn't handle newlines correctly currently.

# File lib/http/accept/quoted_string.rb, line 46
def self.quote(value, force = false)
        if value =~ /"/ or force
                "\"#{value.gsub(/["\\]/, "\\\\\\0")}\""
        else
                return value
        end
end
unquote(value, normalize_whitespace = true) click to toggle source

Unquote a “quoted-string” value according to tools.ietf.org/html/rfc7230#section-3.2.6 It should already match the QUOTED_STRING pattern above by the parser.

# File lib/http/accept/quoted_string.rb, line 32
def self.unquote(value, normalize_whitespace = true)
        value = value[1...-1]
        
        value.gsub!(/\\(.)/, '\1') 
        
        if normalize_whitespace
                # LWS = [CRLF] 1*( SP | HT )
                value.gsub!(/[\r\n]+\s+/, ' ')
        end
        
        return value
end