summaryrefslogtreecommitdiffstats
path: root/lib/yaml
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
commit79fac09d456e6b158b57aa6379e9410b2cc7b6db (patch)
tree6931c25c8907d5e481be1281be1a30297a3fff53 /lib/yaml
parent123d566fc9926ffb9b0e2ba84e9c84504fea5491 (diff)
downloadruby-79fac09d456e6b158b57aa6379e9410b2cc7b6db.tar.gz
ruby-79fac09d456e6b158b57aa6379e9410b2cc7b6db.tar.xz
ruby-79fac09d456e6b158b57aa6379e9410b2cc7b6db.zip
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@3937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/yaml')
-rw-r--r--lib/yaml/constants.rb12
-rw-r--r--lib/yaml/emitter.rb6
-rw-r--r--lib/yaml/encoding.rb96
-rw-r--r--lib/yaml/rubytypes.rb11
4 files changed, 15 insertions, 110 deletions
diff --git a/lib/yaml/constants.rb b/lib/yaml/constants.rb
index 21aee7e0a..fb833d307 100644
--- a/lib/yaml/constants.rb
+++ b/lib/yaml/constants.rb
@@ -15,19 +15,19 @@ module YAML
WORD_CHAR = 'A-Za-z0-9'
PRINTABLE_CHAR = '-_A-Za-z0-9!?/()$\'". '
NOT_PLAIN_CHAR = '\x7f\x0-\x1f\x80-\x9f'
- ESCAPE_CHAR = '[\\x00-\\x08\\x0b-\\x0d\\x0e-\\x1f]'
+ ESCAPE_CHAR = '[\\x00-\\x09\\x0b-\\x1f]'
INDICATOR_CHAR = '*&!|\\\\^@%{}[]='
SPACE_INDICATORS = '-#:,?'
RESTRICTED_INDICATORS = '#:,}]'
DNS_COMP_RE = "\\w(?:[-\\w]*\\w)?"
DNS_NAME_RE = "(?:(?:#{DNS_COMP_RE}\\.)+#{DNS_COMP_RE}|#{DNS_COMP_RE})"
- ESCAPES = %w{\z \x01 \x02 \x03 \x04 \x05 \x06 \a
+ ESCAPES = %w{\x00 \x01 \x02 \x03 \x04 \x05 \x06 \a
\x08 \t \n \v \f \r \x0e \x0f
\x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17
\x18 \x19 \x1a \e \x1c \x1d \x1e \x1f
}
UNESCAPES = {
- 'z' => "\x00", 'a' => "\x07", 'b' => "\x08", 't' => "\x09",
+ 'a' => "\x07", 'b' => "\x08", 't' => "\x09",
'n' => "\x0a", 'v' => "\x0b", 'f' => "\x0c",
'r' => "\x0d", 'e' => "\x1b", '\\' => '\\',
}
@@ -41,11 +41,5 @@ module YAML
:WidthType => 'absolute', :BestWidth => 80,
:UseBlock => false, :UseFold => false, :Encoding => :None
}
- TRANSFER_DOMAINS = {
- 'yaml.org,2002' => {},
- 'ruby.yaml.org,2002' => {}
- }
- PRIVATE_TYPES = {}
- IMPLICIT_TYPES = [ 'null', 'bool', 'time', 'int', 'float' ]
end
diff --git a/lib/yaml/emitter.rb b/lib/yaml/emitter.rb
index 4b8541c2c..66c7a6e81 100644
--- a/lib/yaml/emitter.rb
+++ b/lib/yaml/emitter.rb
@@ -60,6 +60,7 @@ module YAML
# Emit plain, normal flowing text
#
def node_text( value, block = '>' )
+ @seq_map = false
valx = value.dup
if @options[:UseBlock]
block = '|'
@@ -89,6 +90,7 @@ module YAML
# Emit a simple, unqouted string
#
def simple( value )
+ @seq_map = false
self << value.to_s
end
@@ -168,6 +170,7 @@ module YAML
#
if val.length.zero?
self << "{}"
+ @seq_map = false
else
if @buffer.length == 1 and @options[:UseHeader] == false and type.length.zero?
@headless = 1
@@ -213,6 +216,7 @@ module YAML
# Quick sequence
#
def seq( type, &e )
+ @seq_map = false
val = Sequence.new
e.call( val )
self << "#{type} " if type.length.nonzero?
@@ -282,7 +286,7 @@ module YAML
@buffer.push( "" )
#p [ self.id, @level, :END ]
if @level < 0
- YAML.internal_to_utf( header + @buffer.to_s[@headless..-1], @options[:Encoding] )
+ header + @buffer.to_s[@headless..-1]
end
end
end
diff --git a/lib/yaml/encoding.rb b/lib/yaml/encoding.rb
index 59491b53b..e361163ac 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
diff --git a/lib/yaml/rubytypes.rb b/lib/yaml/rubytypes.rb
index 92aee82da..b2ac61584 100644
--- a/lib/yaml/rubytypes.rb
+++ b/lib/yaml/rubytypes.rb
@@ -295,19 +295,20 @@ class String
if complex
if self.is_binary_data?
out.binary_base64( self )
+ elsif self =~ /^ |#{YAML::ESCAPE_CHAR}| $/
+ complex = false
else
out.node_text( self )
end
- else
+ end
+ if not complex
ostr = if out.options[:KeepValue]
self
elsif empty?
"''"
- elsif YAML.detect_implicit( self ) != 'str'
+ elsif self =~ /^[^#{YAML::WORD_CHAR}]|#{YAML::ESCAPE_CHAR}|[#{YAML::SPACE_INDICATORS}]( |$)| $|\n|\'/
"\"#{YAML.escape( self )}\""
- elsif self =~ /#{YAML::ESCAPE_CHAR}|[#{YAML::SPACE_INDICATORS}] |\n|\'/
- "\"#{YAML.escape( self )}\""
- elsif self =~ /^[^#{YAML::WORD_CHAR}]/
+ elsif YAML.detect_implicit( self ) != 'str'
"\"#{YAML.escape( self )}\""
else
self