Expand description
ruby literal encoder.
encodes untrusted strings for safe embedding in ruby source literals.
for_ruby_string— safe for ruby double-quoted string literals ("...")
§encoding rules
the encoder uses ruby’s native escape syntax:
- named escapes:
\a,\b,\t,\n,\v,\f,\r,\e,\\ - double quote →
\" - hash sign →
\#(prevents#{},#$,#@interpolation) - other C0 controls and DEL →
\xHH - unicode non-characters → space
- non-ASCII unicode passes through (ruby 2.0+ source files are UTF-8 by default)
the output is safe for double-quoted string literals only. ruby
single-quoted strings ('...') use different escape rules and are
not covered by this encoder.
Functions§
- for_
ruby_ string - encodes
inputfor safe embedding in a ruby double-quoted string literal ("..."). - write_
ruby_ string - writes the ruby-string-encoded form of
inputtoout.