summaryrefslogtreecommitdiff
path: root/lib/yaml/encoding.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/yaml/encoding.rb')
-rw-r--r--lib/yaml/encoding.rb96
1 files changed, 1 insertions, 95 deletions
diff --git a/lib/yaml/encoding.rb b/lib/yaml/encoding.rb
index 59491b53b7..e361163ac6 100644
--- a/lib/yaml/encoding.rb
+++ b/lib/yaml/encoding.rb
@@ -5,100 +5,6 @@
module YAML
#
- # Encodings ( $-K to ICONV )
- #
- CHARSETS = {
- 'NONE' => 'LATIN1',
- 'ASCII' => 'US-ASCII',
- 'UTF-8' => 'UTF-8',
- 'EUC' => 'EUC-JP',
- 'SJIS' => 'SHIFT-JIS'
- }
-
- #
- # YAML documents can be in UTF-8, UTF-16 or UTF-32
- # So let's read and write in Unicode
- #
-
- @@unicode = false
- begin
- require 'iconv'
- DEFAULTS[:Encoding] = :Utf8
- rescue LoadError
- end
-
- def YAML.unicode; @@unicode; end
- def YAML.unicode=( bool ); @@unicode = bool; end
-
- #
- # Unicode conversion
- #
-
- def YAML.utf_to_internal( str, from_enc )
- return unless str
- to_enc = CHARSETS[$-K]
- case from_enc
- when :Utf32
- Iconv.iconv( to_enc, 'UTF-32', str )[0]
- when :Utf16
- Iconv.iconv( to_enc, 'UTF-16', str )[0]
- when :Utf8
- Iconv.iconv( to_enc, 'UTF-8', str )[0]
- when :None
- str
- else
- raise YAML::Error, ERROR_UNSUPPORTED_ENCODING % from_enc.inspect
- end
- end
-
- def YAML.internal_to_utf( str, to_enc )
- return unless str
- from_enc = CHARSETS[$-K]
- case to_enc
- when :Utf32
- Iconv.iconv( 'UTF-32', from_enc, str )[0]
- when :Utf16
- Iconv.iconv( 'UTF-16', from_enc, str )[0]
- when :Utf8
- Iconv.iconv( 'UTF-8', from_enc, str )[0]
- when :None
- str
- else
- raise YAML::Error, ERROR_UNSUPPORTED_ENCODING % to_enc.inspect
- end
- end
-
- def YAML.sniff_encoding( str )
- unless YAML::unicode
- :None
- else
- case str
- when /^\x00\x00\xFE\xFF/ # UTF-32
- :Utf32
- when /^\xFE\xFF/ # UTF-32BE
- :Utf16
- else
- :Utf8
- end
- end
- end
-
- def YAML.enc_separator( enc )
- case enc
- when :Utf32
- "\000\000\000\n"
- when :Utf16
- "\000\n"
- when :Utf8
- "\n"
- when :None
- "\n"
- else
- raise YAML::Error, ERROR_UNSUPPORTED_ENCODING % enc.inspect
- end
- end
-
- #
# Escape the string, condensing common escapes
#
def YAML.escape( value )
@@ -109,7 +15,7 @@ module YAML
# Unescape the condenses escapes
#
def YAML.unescape( value )
- value.gsub( /\\(?:([nevbr\\fartz])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { |x|
+ value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { |x|
if $3
["#$3".hex ].pack('U*')
elsif $2