Split a string into lines ignoring form feed and other chars. This mimics how the Python parser splits source code.
(source, maxlines=None)
| 317 | |
| 318 | _line_pattern = None |
| 319 | def _splitlines_no_ff(source, maxlines=None): |
| 320 | """Split a string into lines ignoring form feed and other chars. |
| 321 | |
| 322 | This mimics how the Python parser splits source code. |
| 323 | """ |
| 324 | global _line_pattern |
| 325 | if _line_pattern is None: |
| 326 | # lazily computed to speedup import time of `ast` |
| 327 | import re |
| 328 | _line_pattern = re.compile(r"(.*?(?:\r\n|\n|\r|$))") |
| 329 | |
| 330 | lines = [] |
| 331 | for lineno, match in enumerate(_line_pattern.finditer(source), 1): |
| 332 | if maxlines is not None and lineno > maxlines: |
| 333 | break |
| 334 | lines.append(match[0]) |
| 335 | return lines |
| 336 | |
| 337 | |
| 338 | def _pad_whitespace(source): |
no test coverage detected