module Webmachine::QuotedString
Helper methods for dealing with the ‘quoted-string’ type often present in header values.
Constants
- QS_ANCHORED
The pattern for a ‘quoted-string’ type, without any other content.
- QUOTED_STRING
The pattern for a ‘quoted-string’ type
Public Instance Methods
escape_quotes(str)
click to toggle source
Escapes quotes within a quoted string.
# File lib/webmachine/quoted_string.rb, line 30 def escape_quotes(str) str.gsub(/"/, '\\"') end
quote(str)
click to toggle source
Ensures that quotes exist around a quoted-string
# File lib/webmachine/quoted_string.rb, line 21 def quote(str) if QS_ANCHORED.match?(str) str else %("#{escape_quotes str}") end end
unescape_quotes(str)
click to toggle source
Unescapes quotes within a quoted string
# File lib/webmachine/quoted_string.rb, line 35 def unescape_quotes(str) str.delete('\\') end
unquote(str)
click to toggle source
Removes surrounding quotes from a quoted-string
# File lib/webmachine/quoted_string.rb, line 12 def unquote(str) if str =~ QS_ANCHORED unescape_quotes $1 else str end end