aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rexml
diff options
context:
space:
mode:
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