diff options
Diffstat (limited to 'ruby_1_9_3/ext/syck/lib/syck/encoding.rb')
-rw-r--r-- | ruby_1_9_3/ext/syck/lib/syck/encoding.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/ruby_1_9_3/ext/syck/lib/syck/encoding.rb b/ruby_1_9_3/ext/syck/lib/syck/encoding.rb new file mode 100644 index 0000000000..dad062994c --- /dev/null +++ b/ruby_1_9_3/ext/syck/lib/syck/encoding.rb @@ -0,0 +1,35 @@ +# +# Handle Unicode-to-Internal conversion +# + +module Syck + + # + # Escape the string, condensing common escapes + # + def self.escape( value, skip = "" ) + warn "#{caller[0]}: YAML.escape is deprecated" if $VERBOSE + value.gsub( /\\/, "\\\\\\" ). + gsub( /"/, "\\\"" ). + gsub( /([\x00-\x1f])/ ) do + skip[$&] || ESCAPES[ $&.unpack("C")[0] ] + end + end + + # + # Unescape the condenses escapes + # + def self.unescape( value ) + warn "#{caller[0]}: YAML.unescape is deprecated" if $VERBOSE + value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { + if $3 + ["#$3".hex ].pack('U*') + elsif $2 + [$2].pack( "H2" ) + else + UNESCAPES[$1] + end + } + end + +end |