summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych/visitors
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-16 06:37:22 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-16 06:37:22 +0000
commita5c577757ece55432acbed341d299ac8849d633f (patch)
treef528ce60dc834b1304c71061ecbf7691edfbe250 /ext/psych/lib/psych/visitors
parent983cbb1aed57665e3a616f40b759f35bf143e091 (diff)
* ext/psych/lib/psych.rb: bump version
* ext/psych/lib/psych/visitors/yaml_tree.rb: fix line width wrapping for long strings. Thanks Jakub Jirutka <jakub@jirutka.cz> * test/psych/test_string.rb: test for change git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych/lib/psych/visitors')
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb32
1 files changed, 16 insertions, 16 deletions
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index 3a6bd1da54..f6427ce807 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/lib/psych/visitors/yaml_tree.rb
@@ -62,13 +62,14 @@ module Psych
def initialize emitter, ss, options
super()
- @started = false
- @finished = false
- @emitter = emitter
- @st = Registrar.new
- @ss = ss
- @options = options
- @coders = []
+ @started = false
+ @finished = false
+ @emitter = emitter
+ @st = Registrar.new
+ @ss = ss
+ @options = options
+ @line_width = options[:line_width]
+ @coders = []
@dispatch_cache = Hash.new do |h,klass|
method = "visit_#{(klass.name || '').split('::').join('_')}"
@@ -301,28 +302,27 @@ module Psych
quote = true
style = Nodes::Scalar::PLAIN
tag = nil
- str = o
if binary?(o)
- str = [o].pack('m').chomp
+ o = [o].pack('m').chomp
tag = '!binary' # FIXME: change to below when syck is removed
#tag = 'tag:yaml.org,2002:binary'
style = Nodes::Scalar::LITERAL
plain = false
quote = false
- elsif o =~ /\n/
+ elsif o =~ /\n[^\Z]/ # match \n except blank line at the end of string
style = Nodes::Scalar::LITERAL
elsif o == '<<'
style = Nodes::Scalar::SINGLE_QUOTED
tag = 'tag:yaml.org,2002:str'
plain = false
quote = false
+ elsif @line_width && o.length > @line_width
+ style = Nodes::Scalar::FOLDED
elsif o =~ /^[^[:word:]][^"]*$/
style = Nodes::Scalar::DOUBLE_QUOTED
- else
- unless String === @ss.tokenize(o)
- style = Nodes::Scalar::SINGLE_QUOTED
- end
+ elsif not String === @ss.tokenize(o)
+ style = Nodes::Scalar::SINGLE_QUOTED
end
ivars = find_ivars o
@@ -333,14 +333,14 @@ module Psych
plain = false
quote = false
end
- @emitter.scalar str, nil, tag, plain, quote, style
+ @emitter.scalar o, nil, tag, plain, quote, style
else
maptag = '!ruby/string'
maptag << ":#{o.class}" unless o.class == ::String
register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK)
@emitter.scalar 'str', nil, nil, true, false, Nodes::Scalar::ANY
- @emitter.scalar str, nil, tag, plain, quote, style
+ @emitter.scalar o, nil, tag, plain, quote, style
dump_ivars o