1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/syck/token.c: re2c no longer compiled with bit vectors. caused

problems for non-ascii characters. [ruby-core:03280]
* ext/syck/implicit.c: ditto.
* ext/syck/bytecode.c: ditto.

* 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/branches/ruby_1_8@6789 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
why 2004-08-18 20:54:40 +00:00
parent 157832d922
commit e1f2cdb6a5
7 changed files with 3877 additions and 2013 deletions

View file

@ -1,3 +1,18 @@
Thu Aug 19 06:07:45 2004 why the lucky stiff <why@ruby-lang.org>
* ext/syck/token.c: re2c no longer compiled with bit vectors. caused
problems for non-ascii characters. [ruby-core:03280]
* ext/syck/implicit.c: ditto.
* ext/syck/bytecode.c: ditto.
* 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:41:33 2004 Minero Aoki <aamine@loveruby.net>
* lib/net/protocol.rb (rbuf_fill): OpenSSL::SSLSocket has its own

View file

@ -1,4 +1,4 @@
/* Generated by re2c 0.9.3 on Fri Jun 18 18:55:09 2004 */
/* Generated by re2c 0.9.3 on Fri Aug 13 11:47:50 2004 */
#line 1 "bytecode.re"
/*
* bytecode.re

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -33,7 +33,7 @@ module YAML
#
# Emit plain, normal flowing text
#
def node_text( value, block = '>' )
def node_text( value, block = nil )
@seq_map = false
valx = value.dup
unless block
@ -45,6 +45,13 @@ module YAML
else
'>'
end
indt = $&.to_i if block =~ /\d+/
if valx =~ /(\A\n*[ \t#]|^---\s+)/
indt = options(:Indent) unless indt.to_i > 0
block += indt.to_s
end
block +=
if valx =~ /\n\Z\n/
"+"
@ -53,19 +60,19 @@ module YAML
else
"-"
end
if valx =~ /\A[ \t#]/
block += options(:Indent).to_s
end
end
if valx =~ /#{YAML::ESCAPE_CHAR}/
valx = YAML::escape( valx )
end
if block[0] == ?>
valx = fold( valx )
end
indt = nil
indt = $&.to_i if block =~ /\d+/
self << block + indent_text( valx, indt ) + "\n"
block += "\n"
if block[0] == ?"
esc_skip = ( "\t\n" unless valx =~ /^[ \t]/ ) || ""
valx = fold( YAML::escape( valx, esc_skip ) + "\"" ).chomp
self << '"' + indent_text( valx, indt, false )
else
if block[0] == ?>
valx = fold( valx )
end
#p [block, indt]
self << block + indent_text( valx, indt )
end
end
#
@ -93,18 +100,25 @@ module YAML
#
# Write a text block with the current indent
#
def indent_text( text, indt = nil )
def indent_text( text, mod, first_line = true )
return "" if text.to_s.empty?
spacing = " " * ( level * ( indt || options(:Indent) ) )
return "\n" + text.gsub( /^([^\n])/, "#{spacing}\\1" )
spacing = indent( mod )
text = text.gsub( /\A([^\n])/, "#{ spacing }\\1" ) if first_line
return text.gsub( /\n^([^\n])/, "\n#{spacing}\\1" )
end
#
# Write a current indent
#
def indent
#p [ self.id, @level, :INDENT ]
return " " * ( level * options(:Indent) )
def indent( mod = nil )
#p [ self.id, level, mod, :INDENT ]
if level <= 0
mod ||= 0
else
mod ||= options(:Indent)
mod += ( level - 1 ) * options(:Indent)
end
return " " * mod
end
#
@ -118,25 +132,9 @@ module YAML
# Folding paragraphs within a column
#
def fold( value )
value.gsub!( /\A\n+/, '' )
folded = $&.to_s
width = (0..options(:BestWidth))
while not value.empty?
last = value.index( /(\n+)/ )
chop_s = false
if width.include?( last )
last += $1.length - 1
elsif width.include?( value.length )
last = value.length
else
last = value.rindex( /[ \t]/, options(:BestWidth) )
chop_s = true
end
folded += value.slice!( 0, width.include?( last ) ? last + 1 : options(:BestWidth) )
folded.chop! if chop_s
folded += "\n" unless value.empty?
end
folded
value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do |s|
$1 || $2 + ( $3 || "\n" )
end
end
#

View file

@ -7,8 +7,12 @@ module YAML
#
# Escape the string, condensing common escapes
#
def YAML.escape( value )
value.gsub( /\\/, "\\\\\\" ).gsub( /"/, "\\\"" ).gsub( /([\x00-\x1f])/ ) { |x| ESCAPES[ x.unpack("C")[0] ] }
def YAML.escape( value, skip = "" )
value.gsub( /\\/, "\\\\\\" ).
gsub( /"/, "\\\"" ).
gsub( /([\x00-\x1f])/ ) do |x|
skip[x] || ESCAPES[ x.unpack("C")[0] ]
end
end
#

View file

@ -315,25 +315,24 @@ class String
}
elsif self.is_binary_data?
out.binary_base64( self )
# elsif self =~ /^ |#{YAML::ESCAPE_CHAR}| $/
# complex = false
elsif self =~ /#{YAML::ESCAPE_CHAR}/
out.node_text( self, '"' )
else
out.node_text( self, to_yaml_fold )
end
end
if not complex
else
ostr = if out.options(:KeepValue)
self
elsif empty?
"''"
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'
"\"#{YAML.escape( self )}\""
out.node_text( self, '"' ); nil
else
self
end
out.simple( ostr )
out.simple( ostr ) unless ostr.nil?
end
}
end