mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
c6e4767068
commit
6fcd0b37b3
3 changed files with 33 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue