Translate more C constructs, categorize identifiers and add (self|yy). prefixes to...
[c_to_python.git] / wrap_repr.py
1 def wrap_repr(text, width):
2   lines = []
3   i = 0
4   while i < len(text):
5     j = i + width
6     if j < len(text):
7       j = max(
8         [
9           text.rfind('(', i, j) + 1,
10           text.rfind('[', i, j) + 1,
11           text.rfind('{', i, j) + 1,
12           text.rfind('.', i, j) + 1,
13           text.rfind(')', i, j + 1),
14           text.rfind(']', i, j + 1),
15           text.rfind('}', i, j + 1),
16           text.rfind(' ', i, j + 1),
17         ]
18       )
19       assert j > 0
20     lines.append(text[i:j] + '\n')
21     i = j
22     while text[i:i + 1] == ' ':
23       i += 1
24   return ''.join(lines)