5 from functools
import reduce
8 A simple word-wrap function that wraps text on exactly width characters.
9 It doesn't split the text in words.
11 return '\n'.
join([ text[width*i:width*(i+1)] \
12 for i
in xrange(int(math.ceil(1.*len(text)/width))) ])
16 A word-wrap function that preserves existing line breaks
17 and most spaces in the text. Expects that existing line
18 breaks are posix newlines (\n).
20 return reduce(
lambda line, word, width=width:
'%s%s%s' %
22 ' \n'[(len(line[line.rfind(
'\n')+1:])
23 + len(word.split(
'\n',1)[0]
30 Similar to wrap_onspace, but enforces the width constraint:
31 words longer than width are split.
33 wordRegex = re.compile(
r'\S{'+str(width)+
r',}')
36 if __name__ ==
'__main__':
38 print ''.
join([
'-']*5)+
'|'
40 print ''.
join([
'-']*5)+
'|'
42 print ''.
join([
'-']*5)+
'|'
static std::string join(char **cmd)