9: def wrap(txt, opts)
10: return "" unless txt && !txt.empty?
11: work = (opts[:scrub] ? scrub(txt) : txt)
12: indent = (opts[:indent] ? opts[:indent] : 0)
13: textLen = @width - indent
14: patt = Regexp.new("^(.{0,#{textLen}})[ \n]")
15: prefix = " " * indent
16:
17: res = []
18:
19: while work.length > textLen
20: if work =~ patt
21: res << $1
22: work.slice!(0, $MATCH.length)
23: else
24: res << work.slice!(0, textLen)
25: end
26: end
27: res << work if work.length.nonzero?
28: prefix + res.join("\n#{prefix}")
29: end