diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-02-05 06:20:57 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-02-05 06:20:57 +0000 |
commit | 8aa895294b8d696489b51a5e69b2986f452da905 (patch) | |
tree | 085fe578ab276ff3be423448a4b9407c60a6dc51 /lib/rdoc/text.rb | |
parent | d8ebf3829f24fcb05ff47a12a9bb83e8b993aeae (diff) |
Import RDoc 3.5.2
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/text.rb')
-rw-r--r-- | lib/rdoc/text.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/rdoc/text.rb b/lib/rdoc/text.rb index 6dec4217e6..501871c8df 100644 --- a/lib/rdoc/text.rb +++ b/lib/rdoc/text.rb @@ -260,5 +260,37 @@ http://rubyforge.org/tracker/?atid=2472&group_id=627&func=browse html end + ## + # Wraps +txt+ to +line_len+ + + def wrap(txt, line_len = 76) + res = [] + sp = 0 + ep = txt.length + + while sp < ep + # scan back for a space + p = sp + line_len - 1 + if p >= ep + p = ep + else + while p > sp and txt[p] != ?\s + p -= 1 + end + if p <= sp + p = sp + line_len + while p < ep and txt[p] != ?\s + p += 1 + end + end + end + res << txt[sp...p] << "\n" + sp = p + sp += 1 while sp < ep and txt[sp] == ?\s + end + + res.join.strip + end + end |