aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/text.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/text.rb')
-rw-r--r--lib/rubygems/text.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/rubygems/text.rb b/lib/rubygems/text.rb
new file mode 100644
index 0000000000..c694e8a9c0
--- /dev/null
+++ b/lib/rubygems/text.rb
@@ -0,0 +1,30 @@
+require 'rubygems'
+
+##
+# A collection of text-wrangling methods
+
+module Gem::Text
+
+ ##
+ # Wraps +text+ to +wrap+ characters and optionally indents by +indent+
+ # characters
+
+ def format_text(text, wrap, indent=0)
+ result = []
+ work = text.dup
+
+ while work.length > wrap do
+ if work =~ /^(.{0,#{wrap}})[ \n]/ then
+ result << $1
+ work.slice!(0, $&.length)
+ else
+ result << work.slice!(0, wrap)
+ end
+ end
+
+ result << work if work.length.nonzero?
+ result.join("\n").gsub(/^/, " " * indent)
+ end
+
+end
+