2003-05-09 17:25:50 -04:00
|
|
|
#
|
|
|
|
# Handle Unicode-to-Internal conversion
|
|
|
|
#
|
|
|
|
|
|
|
|
module YAML
|
|
|
|
|
|
|
|
#
|
|
|
|
# Escape the string, condensing common escapes
|
|
|
|
#
|
2004-08-18 16:42:09 -04:00
|
|
|
def YAML.escape( value, skip = "" )
|
|
|
|
value.gsub( /\\/, "\\\\\\" ).
|
|
|
|
gsub( /"/, "\\\"" ).
|
* ext/json/lib/json/pure/generator.rb,
ext/json/lib/json/pure/parser.rb, ext/openssl/lib/openssl/x509.rb,
ext/win32ole/sample/olegen.rb, lib/date/format.rb, lib/irb/context.rb,
lib/irb/workspace.rb, lib/net/http.rb, lib/net/imap.rb,
lib/rdoc/generator.rb, lib/rdoc/markup/to_html.rb,
lib/rdoc/markup/to_latex.rb, lib/rdoc/parsers/parse_c.rb,
lib/rdoc/ri/formatter.rb, lib/rexml/parsers/baseparser.rb,
lib/rexml/quickpath.rb, lib/rexml/text.rb, lib/rss/parser.rb,
lib/uri/common.rb, lib/uri/generic.rb, lib/webrick/httpresponse.rb,
lib/webrick/httpservlet/filehandler.rb, lib/yaml/baseemitter.rb,
lib/yaml/encoding.rb: performance tuning arround String#gsub.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15442 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-02-12 01:18:06 -05:00
|
|
|
gsub( /([\x00-\x1f])/ ) do
|
|
|
|
skip[$&] || ESCAPES[ $&.unpack("C")[0] ]
|
2004-08-18 16:42:09 -04:00
|
|
|
end
|
2003-05-09 17:25:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Unescape the condenses escapes
|
|
|
|
#
|
|
|
|
def YAML.unescape( value )
|
* ext/json/lib/json/pure/generator.rb,
ext/json/lib/json/pure/parser.rb, ext/openssl/lib/openssl/x509.rb,
ext/win32ole/sample/olegen.rb, lib/date/format.rb, lib/irb/context.rb,
lib/irb/workspace.rb, lib/net/http.rb, lib/net/imap.rb,
lib/rdoc/generator.rb, lib/rdoc/markup/to_html.rb,
lib/rdoc/markup/to_latex.rb, lib/rdoc/parsers/parse_c.rb,
lib/rdoc/ri/formatter.rb, lib/rexml/parsers/baseparser.rb,
lib/rexml/quickpath.rb, lib/rexml/text.rb, lib/rss/parser.rb,
lib/uri/common.rb, lib/uri/generic.rb, lib/webrick/httpresponse.rb,
lib/webrick/httpservlet/filehandler.rb, lib/yaml/baseemitter.rb,
lib/yaml/encoding.rb: performance tuning arround String#gsub.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15442 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-02-12 01:18:06 -05:00
|
|
|
value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) {
|
2003-05-09 17:25:50 -04:00
|
|
|
if $3
|
|
|
|
["#$3".hex ].pack('U*')
|
|
|
|
elsif $2
|
2009-03-05 22:56:38 -05:00
|
|
|
[$2].pack( "H2" )
|
2003-05-09 17:25:50 -04:00
|
|
|
else
|
2009-03-05 22:56:38 -05:00
|
|
|
UNESCAPES[$1]
|
2003-05-09 17:25:50 -04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|