Return a `TOMLDecodeError` where error message is suffixed with coordinates in source.
(src: str, pos: Pos, msg: str)
| 650 | |
| 651 | |
| 652 | def suffixed_err(src: str, pos: Pos, msg: str) -> TOMLDecodeError: |
| 653 | """Return a `TOMLDecodeError` where error message is suffixed with |
| 654 | coordinates in source.""" |
| 655 | |
| 656 | def coord_repr(src: str, pos: Pos) -> str: |
| 657 | if pos >= len(src): |
| 658 | return "end of document" |
| 659 | line = src.count("\n", 0, pos) + 1 |
| 660 | if line == 1: |
| 661 | column = pos + 1 |
| 662 | else: |
| 663 | column = pos - src.rindex("\n", 0, pos) |
| 664 | return f"line {line}, column {column}" |
| 665 | |
| 666 | return TOMLDecodeError(f"{msg} (at {coord_repr(src, pos)})") |
| 667 | |
| 668 | |
| 669 | def is_unicode_scalar_value(codepoint: int) -> bool: |
no test coverage detected