Pretty prints the given string to break at an occurrence of split where necessary to avoid lines longer than maxlen. This will overflow the line if no convenient occurrence of split is found
(string, maxlen=75, split=' ')
| 176 | return '\n'.join(map(formatline, *cols)) |
| 177 | |
| 178 | def prettyPrint(string, maxlen=75, split=' '): |
| 179 | """Pretty prints the given string to break at an occurrence of |
| 180 | split where necessary to avoid lines longer than maxlen. |
| 181 | |
| 182 | This will overflow the line if no convenient occurrence of split |
| 183 | is found""" |
| 184 | |
| 185 | # Tack on the splitting character to guarantee a final match |
| 186 | string += split |
| 187 | |
| 188 | lines = [] |
| 189 | oldeol = 0 |
| 190 | eol = 0 |
| 191 | while not (eol == -1 or eol == len(string)-1): |
| 192 | eol = string.rfind(split, oldeol, oldeol+maxlen+len(split)) |
| 193 | lines.append(string[oldeol:eol]) |
| 194 | oldeol = eol + len(split) |
| 195 | |
| 196 | return lines |
| 197 | |
| 198 | def nukenewlines(string): |
| 199 | """Strip newlines and any trailing/following whitespace; rejoin |
no test coverage detected