mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/yaml/baseemitter.rb: folding now handles double-quoted strings,
fixed problem with extra line feeds at end of folding, whitespace opening scalar blocks. * lib/yaml/rubytypes.rb: subtelties in handling strings with non-printable characters and odd whitespace patterns. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b79d77197f
commit
5e07e55204
4 changed files with 39 additions and 21 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
Thu Aug 19 03:07:00 2004 why the lucky stiff <why@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/yaml/baseemitter.rb: folding now handles double-quoted strings,
|
||||||
|
fixed problem with extra line feeds at end of folding, whitespace
|
||||||
|
opening scalar blocks.
|
||||||
|
|
||||||
|
* lib/yaml/rubytypes.rb: subtelties in handling strings with
|
||||||
|
non-printable characters and odd whitespace patterns.
|
||||||
|
|
||||||
Wed Aug 18 23:44:20 2004 Minero Aoki <aamine@loveruby.net>
|
Wed Aug 18 23:44:20 2004 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* lib/net/protocol.rb (rbuf_fill): OpenSSL::SSLSocket has its own
|
* lib/net/protocol.rb (rbuf_fill): OpenSSL::SSLSocket has its own
|
||||||
|
|
|
@ -47,7 +47,7 @@ module YAML
|
||||||
end
|
end
|
||||||
|
|
||||||
indt = $&.to_i if block =~ /\d+/
|
indt = $&.to_i if block =~ /\d+/
|
||||||
if valx =~ /(\A[ \t#]|^---\s+)/
|
if valx =~ /(\A\n*[ \t#]|^---\s+)/
|
||||||
indt = options(:Indent) unless indt.to_i > 0
|
indt = options(:Indent) unless indt.to_i > 0
|
||||||
block += indt.to_s
|
block += indt.to_s
|
||||||
end
|
end
|
||||||
|
@ -61,14 +61,18 @@ module YAML
|
||||||
"-"
|
"-"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if valx =~ /#{YAML::ESCAPE_CHAR}/
|
block += "\n"
|
||||||
valx = YAML::escape( valx )
|
if block[0] == ?"
|
||||||
end
|
esc_skip = ( "\t\n" unless valx =~ /^[ \t]/ ) || ""
|
||||||
if block[0] == ?>
|
valx = fold( YAML::escape( valx, esc_skip ) + "\"" ).chomp
|
||||||
valx = fold( valx )
|
self << '"' + indent_text( valx, indt, false )
|
||||||
end
|
else
|
||||||
#p [block, indt]
|
if block[0] == ?>
|
||||||
self << block + indent_text( valx, indt ) + "\n"
|
valx = fold( valx )
|
||||||
|
end
|
||||||
|
#p [block, indt]
|
||||||
|
self << block + indent_text( valx, indt )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -96,10 +100,11 @@ module YAML
|
||||||
#
|
#
|
||||||
# Write a text block with the current indent
|
# Write a text block with the current indent
|
||||||
#
|
#
|
||||||
def indent_text( text, mod = nil )
|
def indent_text( text, mod, first_line = true )
|
||||||
return "" if text.to_s.empty?
|
return "" if text.to_s.empty?
|
||||||
spacing = indent( mod )
|
spacing = indent( mod )
|
||||||
return "\n" + text.gsub( /^([^\n])/, "#{spacing}\\1" )
|
text = text.gsub( /\A([^\n])/, "#{ spacing }\\1" ) if first_line
|
||||||
|
return text.gsub( /\n^([^\n])/, "\n#{spacing}\\1" )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -127,7 +132,7 @@ module YAML
|
||||||
# Folding paragraphs within a column
|
# Folding paragraphs within a column
|
||||||
#
|
#
|
||||||
def fold( value )
|
def fold( value )
|
||||||
value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]))|$)/ ) do |s|
|
value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do |s|
|
||||||
$1 || $2 + ( $3 || "\n" )
|
$1 || $2 + ( $3 || "\n" )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,8 +7,12 @@ module YAML
|
||||||
#
|
#
|
||||||
# Escape the string, condensing common escapes
|
# Escape the string, condensing common escapes
|
||||||
#
|
#
|
||||||
def YAML.escape( value )
|
def YAML.escape( value, skip = "" )
|
||||||
value.gsub( /\\/, "\\\\\\" ).gsub( /"/, "\\\"" ).gsub( /([\x00-\x1f])/ ) { |x| ESCAPES[ x.unpack("C")[0] ] }
|
value.gsub( /\\/, "\\\\\\" ).
|
||||||
|
gsub( /"/, "\\\"" ).
|
||||||
|
gsub( /([\x00-\x1f])/ ) do |x|
|
||||||
|
skip[x] || ESCAPES[ x.unpack("C")[0] ]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- vim: sw=4 ts=4
|
# -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- vim: sw=4 ts=4
|
||||||
require 'date'
|
require 'date'
|
||||||
|
require 'yaml/compat'
|
||||||
#
|
#
|
||||||
# Type conversions
|
# Type conversions
|
||||||
#
|
#
|
||||||
|
@ -315,25 +316,24 @@ class String
|
||||||
}
|
}
|
||||||
elsif self.is_binary_data?
|
elsif self.is_binary_data?
|
||||||
out.binary_base64( self )
|
out.binary_base64( self )
|
||||||
# elsif self =~ /^ |#{YAML::ESCAPE_CHAR}| $/
|
elsif self =~ /#{YAML::ESCAPE_CHAR}/
|
||||||
# complex = false
|
out.node_text( self, '"' )
|
||||||
else
|
else
|
||||||
out.node_text( self, to_yaml_fold )
|
out.node_text( self, to_yaml_fold )
|
||||||
end
|
end
|
||||||
end
|
else
|
||||||
if not complex
|
|
||||||
ostr = if out.options(:KeepValue)
|
ostr = if out.options(:KeepValue)
|
||||||
self
|
self
|
||||||
elsif empty?
|
elsif empty?
|
||||||
"''"
|
"''"
|
||||||
elsif self =~ /^[^#{YAML::WORD_CHAR}\/]| \#|#{YAML::ESCAPE_CHAR}|[#{YAML::SPACE_INDICATORS}]( |$)| $|\n|\'/
|
elsif self =~ /^[^#{YAML::WORD_CHAR}\/]| \#|#{YAML::ESCAPE_CHAR}|[#{YAML::SPACE_INDICATORS}]( |$)| $|\n|\'/
|
||||||
"\"#{YAML.escape( self )}\""
|
out.node_text( self, '"' ); nil
|
||||||
elsif YAML.detect_implicit( self ) != 'str'
|
elsif YAML.detect_implicit( self ) != 'str'
|
||||||
"\"#{YAML.escape( self )}\""
|
out.node_text( self, '"' ); nil
|
||||||
else
|
else
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
out.simple( ostr )
|
out.simple( ostr ) unless ostr.nil?
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue