Module: Webmachine::QuotedString
- Included in:
- Decision::Helpers, ETag
- Defined in:
- lib/webmachine/quoted_string.rb
Overview
Helper methods for dealing with the ‘quoted-string’ type often present in header values.
Constant Summary collapse
- QUOTED_STRING =
The pattern for a ‘quoted-string’ type
/"((?:\\"|[^"])*)"/.freeze
- QS_ANCHORED =
The pattern for a ‘quoted-string’ type, without any other content.
/^#{QUOTED_STRING}$/.freeze
Instance Method Summary collapse
-
#escape_quotes(str) ⇒ Object
Escapes quotes within a quoted string.
-
#quote(str) ⇒ Object
Ensures that quotes exist around a quoted-string.
-
#unescape_quotes(str) ⇒ Object
Unescapes quotes within a quoted string.
-
#unquote(str) ⇒ Object
Removes surrounding quotes from a quoted-string.
Instance Method Details
#escape_quotes(str) ⇒ Object
Escapes quotes within a quoted string.
30 31 32 |
# File 'lib/webmachine/quoted_string.rb', line 30 def escape_quotes(str) str.gsub(/"/, '\\"') end |
#quote(str) ⇒ Object
Ensures that quotes exist around a quoted-string
21 22 23 24 25 26 27 |
# File 'lib/webmachine/quoted_string.rb', line 21 def quote(str) if str =~ QS_ANCHORED str else %Q{"#{escape_quotes str}"} end end |
#unescape_quotes(str) ⇒ Object
Unescapes quotes within a quoted string
35 36 37 |
# File 'lib/webmachine/quoted_string.rb', line 35 def unescape_quotes(str) str.gsub(%r{\\}, '') end |
#unquote(str) ⇒ Object
Removes surrounding quotes from a quoted-string
12 13 14 15 16 17 18 |
# File 'lib/webmachine/quoted_string.rb', line 12 def unquote(str) if str =~ QS_ANCHORED unescape_quotes $1 else str end end |