summaryrefslogtreecommitdiff
path: root/lib/rexml
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-18 14:25:03 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-18 14:25:03 +0000
commit6fcd0b37b3cf9b37f3bd2833cef614ae22f3f7ca (patch)
treee1dc52abc9ffab5fb74e932c7b36d0e1d142765d /lib/rexml
parentc6e4767068df673200351c23c203c22731e6102a (diff)
* lib/rexml/formatters/pretty.rb (REXML::Formatters::Pretty#wrap):
REXML::Formatters::Pretty#wrap used a recursive method call to format text. This switches it to use an iterative approach. [ruby-core:33245] Patch by Jeremy Evans. Thanks!!! * test/rexml/test_core.rb: add a test for it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml')
-rw-r--r--lib/rexml/formatters/pretty.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/rexml/formatters/pretty.rb b/lib/rexml/formatters/pretty.rb
index 17d217d1dc..1747397700 100644
--- a/lib/rexml/formatters/pretty.rb
+++ b/lib/rexml/formatters/pretty.rb
@@ -126,11 +126,13 @@ module REXML
end
def wrap(string, width)
- # Recursively wrap string at width.
- return string if string.length <= width
- place = string.rindex(' ', width) # Position in string with last ' ' before cutoff
- return string if place.nil?
- return string[0,place] + "\n" + wrap(string[place+1..-1], width)
+ parts = []
+ while string.length > width and place = string.rindex(' ', width)
+ parts << string[0...place]
+ string = string[place+1..-1]
+ end
+ parts << string
+ parts.join("\n")
end
end