From 8aa895294b8d696489b51a5e69b2986f452da905 Mon Sep 17 00:00:00 2001 From: drbrain Date: Sat, 5 Feb 2011 06:20:57 +0000 Subject: Import RDoc 3.5.2 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/text.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/rdoc/text.rb') 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 -- cgit v1.2.3