1
## \file wordwrap.rb small word-wrapping utility
2
# copyright (c) 2009 by Vincent Fourmond
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details (in the COPYING file).
14
require 'ctioga2/utils'
15
require 'ctioga2/commands/commands'
16
require 'ctioga2/commands/parsers/command-line'
20
Version::register_svn_info('$Revision: 131 $', '$Date: 2010-01-14 22:51:09 +0100 (Thu, 14 Jan 2010) $')
27
# A small utility class to do word wrapping.
29
# \todo Maybe this belongs in Utils ?
32
# A regex matching word separation.
33
attr_accessor :word_sep
35
# What to replace the separator with
36
attr_accessor :new_sep
38
def initialize(ws = /\s+/, ns = " ")
43
# Split strings into an array of string whose length is each
46
words = str.split(@word_sep)
49
if (lines.last.size + w.size + @new_sep.size) <= cols
50
lines.last.concat("#{@new_sep}#{w}")
58
# Calls #wrap for default values of the parameters
59
def self.wrap(str, cols)
60
return WordWrapper.new.wrap(str, cols)