Line | |
---|
1 | #
|
---|
2 | # Handle Unicode-to-Internal conversion
|
---|
3 | #
|
---|
4 |
|
---|
5 | module YAML
|
---|
6 |
|
---|
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 |x|
|
---|
14 | skip[x] || ESCAPES[ x.unpack("C")[0] ]
|
---|
15 | end
|
---|
16 | end
|
---|
17 |
|
---|
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}))/ ) { |x|
|
---|
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
|
---|
32 |
|
---|
33 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.