Split a string into lines ignoring form feed and other chars. This mimics how the Python parser splits source code.
(source, maxlines=None)
| 331 | |
| 332 | _line_pattern = None |
| 333 | def _splitlines_no_ff(source, maxlines=None): |
| 334 | """Split a string into lines ignoring form feed and other chars. |
| 335 | |
| 336 | This mimics how the Python parser splits source code. |
| 337 | """ |
| 338 | global _line_pattern |
| 339 | if _line_pattern is None: |
| 340 | # lazily computed to speedup import time of `ast` |
| 341 | import re |
| 342 | _line_pattern = re.compile(r"(.*?(?:\r\n|\n|\r|$))") |
| 343 | |
| 344 | lines = [] |
| 345 | for lineno, match in enumerate(_line_pattern.finditer(source), 1): |
| 346 | if maxlines is not None and lineno > maxlines: |
| 347 | break |
| 348 | lines.append(match[0]) |
| 349 | return lines |
| 350 | |
| 351 | |
| 352 | def _pad_whitespace(source): |
no test coverage detected
searching dependent graphs…