summaryrefslogtreecommitdiff
path: root/lib/yaml/encoding.rb
diff options
context:
space:
mode:
authorwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-10 14:15:27 +0000
committerwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-10 14:15:27 +0000
commite921ea2d78f693c57fcb289faff3fc126dc8617a (patch)
tree6931c25c8907d5e481be1281be1a30297a3fff53 /lib/yaml/encoding.rb
parent3079dcab4ad9e7624703d772f6fc54dc10e45bce (diff)
* ext/syck/token.c: preserve newlines prepended to a block.
* ext/syck/implicit.c (syck_match_implicit): added !merge and !default. * lib/yaml/constants.rb: remove '\z' escape. * lib/yaml/emitter.rb: ensure reset of @seq_map shortcut flag. * lib/yaml/encoding.rb: remove Unicode translation methods. * lib/yaml/rubytypes.rb: improved round-tripping of Strings. [ruby-core:1134] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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