Return a normalized version of string s with newlines, tabs and C style comments ("/* ... */") replaced with spaces. Multiple spaces are replaced with a single space. >>> normalize(" /* nothing */ foo\tfoo /* bar */ foo ") 'foo foo foo'
(s)
| 48 | |
| 49 | |
| 50 | def normalize(s): |
| 51 | """Return a normalized version of string s with newlines, tabs and C style comments ("/* ... */") |
| 52 | replaced with spaces. Multiple spaces are replaced with a single space. |
| 53 | |
| 54 | >>> normalize(" /* nothing */ foo\tfoo /* bar */ foo ") |
| 55 | 'foo foo foo' |
| 56 | """ |
| 57 | assert type(s) is str |
| 58 | s = s.replace("\n", " ") |
| 59 | s = s.replace("\t", " ") |
| 60 | s = re.sub(r"/\*.*?\*/", " ", s) |
| 61 | s = re.sub(" {2,}", " ", s) |
| 62 | return s.strip() |
| 63 | |
| 64 | |
| 65 | ESCAPE_MAP = { |
no test coverage detected