7 A simple word-wrap function that wraps text on exactly width characters.
8 It doesn't split the text in words.
10 return '\n'.
join([ text[width*i:width*(i+1)] \
11 for i
in xrange(int(math.ceil(1.*len(text)/width))) ])
15 A word-wrap function that preserves existing line breaks
16 and most spaces in the text. Expects that existing line
17 breaks are posix newlines (\n).
19 return reduce(
lambda line, word, width=width:
'%s%s%s' %
21 ' \n'[(len(line[line.rfind(
'\n')+1:])
22 + len(word.split(
'\n',1)[0]
29 Similar to wrap_onspace, but enforces the width constraint:
30 words longer than width are split.
32 wordRegex = re.compile(
r'\S{'+str(width)+
r',}')
35 if __name__ ==
'__main__':
37 print ''.
join([
'-']*5)+
'|'
39 print ''.
join([
'-']*5)+
'|'
41 print ''.
join([
'-']*5)+
'|'
static std::string join(char **cmd)