* transcode_data.h (rb_transcoder_stateful_type_t): defined.
[ruby-svn.git] / lib / yaml / encoding.rb
blob57dc55360623bc3e6be8db91b75fe29e6d246336
2 # Handle Unicode-to-Internal conversion
5 module YAML
7         #
8         # Escape the string, condensing common escapes
9         #
10         def YAML.escape( value, skip = "" )
11                 value.gsub( /\\/, "\\\\\\" ).
12               gsub( /"/, "\\\"" ).
13               gsub( /([\x00-\x1f])/ ) do
14                  skip[$&] || ESCAPES[ $&.unpack("C")[0] ]
15              end
16         end
18         #
19         # Unescape the condenses escapes
20         #
21         def YAML.unescape( value )
22                 value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) {
23                         if $3
24                                 ["#$3".hex ].pack('U*')
25                         elsif $2
26                                 [$2].pack( "H2" ) 
27                         else
28                                 UNESCAPES[$1] 
29                         end
30                 }
31         end
33 end