diff options
author | why <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-05-25 14:57:25 +0000 |
---|---|---|
committer | why <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-05-25 14:57:25 +0000 |
commit | ca1dca02b029a7d6b8c9a3a5cc21221346f792bc (patch) | |
tree | ddaf1ae454ef0577c631ed5fe8114d8d64587d51 /lib/yaml | |
parent | 82572952ecf82aad6bc47a51e3d63d7b52858b2d (diff) |
* ext/syck/syck.c (syck_new_parser): clear parser on init.
thanks, ts. [ruby-core:02931]
* ext/syck/token.c (sycklex_yaml_utf8): buffer underflow.
thanks, ts. [ruby-core:02929]
* lib/yaml/baseemitter.rb (indent_text): simpler flow block code.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6403 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/yaml')
-rw-r--r-- | lib/yaml/baseemitter.rb | 32 | ||||
-rw-r--r-- | lib/yaml/rubytypes.rb | 4 |
2 files changed, 12 insertions, 24 deletions
diff --git a/lib/yaml/baseemitter.rb b/lib/yaml/baseemitter.rb index da908d98dc..2881d424b4 100644 --- a/lib/yaml/baseemitter.rb +++ b/lib/yaml/baseemitter.rb @@ -45,9 +45,13 @@ module YAML else '>' end - if valx =~ /\A[ \t#]/ - block += options(:Indent).to_s + + indt = $&.to_i if block =~ /\d+/ + if valx =~ /(\A[ \t#]|^---\s+)/ + indt = options(:Indent) unless indt.to_i > 0 + block += indt.to_s end + block += if valx =~ /\n\Z\n/ "+" @@ -63,8 +67,6 @@ module YAML if block[0] == ?> valx = fold( valx ) end - indt = nil - indt = $&.to_i if block =~ /\d+/ #p [block, indt] self << block + indent_text( valx, indt ) + "\n" end @@ -125,25 +127,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]))|$)/ ) do |s| + $1 || $2 + ( $3 || "\n" ) + end end # diff --git a/lib/yaml/rubytypes.rb b/lib/yaml/rubytypes.rb index 239688a6b2..f73eaf2dcd 100644 --- a/lib/yaml/rubytypes.rb +++ b/lib/yaml/rubytypes.rb @@ -392,7 +392,9 @@ class Range end def to_yaml( opts = {} ) YAML::quick_emit( self.object_id, opts ) { |out| - if self.begin.is_complex_yaml? or self.end.is_complex_yaml? or not to_yaml_properties.empty? + if self.begin.is_complex_yaml? or self.begin.respond_to? :to_str or + self.end.is_complex_yaml? or self.end.respond_to? :to_str or + not to_yaml_properties.empty? out.map( to_yaml_type ) { |map| map.add( 'begin', self.begin ) map.add( 'end', self.end ) |