Module: Reco::Util
- Defined in:
- lib/reco/util.rb
Constant Summary collapse
- SPECIAL_CHARACTERS =
{ "\\" => '\\\\', "\b" => '\\b', "\f" => '\\f', "\n" => '\\n', "\r" => '\\r', "\t" => '\\t' }
Class Method Summary collapse
Class Method Details
.inspect_string(string) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/reco/util.rb', line 11 def self.inspect_string(string) string.gsub!(/[\x00-\x1f\\]/) do |character| if SPECIAL_CHARACTERS[character] SPECIAL_CHARACTERS[character] else code = character.ord.to_s 16 code = "0#{code}" if code.length == 1 "\\u00#{code}" end end "'" + string.gsub("'", "\\\\'") + "'" end |