Split a string into lines ignoring form feed and other chars. This mimics how the Python parser splits source code.
(source)
| 305 | |
| 306 | |
| 307 | def _splitlines_no_ff(source): |
| 308 | """Split a string into lines ignoring form feed and other chars. |
| 309 | |
| 310 | This mimics how the Python parser splits source code. |
| 311 | """ |
| 312 | idx = 0 |
| 313 | lines = [] |
| 314 | next_line = '' |
| 315 | while idx < len(source): |
| 316 | c = source[idx] |
| 317 | next_line += c |
| 318 | idx += 1 |
| 319 | # Keep \r\n together |
| 320 | if c == '\r' and idx < len(source) and source[idx] == '\n': |
| 321 | next_line += '\n' |
| 322 | idx += 1 |
| 323 | if c in '\r\n': |
| 324 | lines.append(next_line) |
| 325 | next_line = '' |
| 326 | |
| 327 | if next_line: |
| 328 | lines.append(next_line) |
| 329 | return lines |
| 330 | |
| 331 | |
| 332 | def _pad_whitespace(source): |
no test coverage detected