Class: JSONString

Inherits:
Object show all
Defined in:
motion/core_ext/object/to_json.rb

Constant Summary collapse

ESCAPED_CHARS =
{
"\u0000" => '\u0000', "\u0001" => '\u0001',
"\u0002" => '\u0002', "\u0003" => '\u0003',
"\u0004" => '\u0004', "\u0005" => '\u0005',
"\u0006" => '\u0006', "\u0007" => '\u0007',
"\u0008" => '\b',     "\u0009" => '\t',
"\u000A" => '\n',     "\u000B" => '\u000B',
"\u000C" => '\f',     "\u000D" => '\r',
"\u000E" => '\u000E', "\u000F" => '\u000F',
"\u0010" => '\u0010', "\u0011" => '\u0011',
"\u0012" => '\u0012', "\u0013" => '\u0013',
"\u0014" => '\u0014', "\u0015" => '\u0015',
"\u0016" => '\u0016', "\u0017" => '\u0017',
"\u0018" => '\u0018', "\u0019" => '\u0019',
"\u001A" => '\u001A', "\u001B" => '\u001B',
"\u001C" => '\u001C', "\u001D" => '\u001D',
"\u001E" => '\u001E', "\u001F" => '\u001F',
"\u2028" => '\u2028', "\u2029" => '\u2029',
'"'  => '\"',
'\\' => '\\\\',
'>' => '\u003E',
'<' => '\u003C',
'&' => '\u0026'}
ESCAPE_REGEX =
/[\u0000-\u001F\u2028\u2029"\\><&]/u

Class Method Summary collapse

Class Method Details

.escape(string) ⇒ Object



67
68
69
# File 'motion/core_ext/object/to_json.rb', line 67

def escape(string)
  %("#{string.gsub ESCAPE_REGEX, ESCAPED_CHARS}")
end