Rewrite C++/CLI spellings to standard C++ ones, or None if not C++/CLI. The rewrite is **byte-length preserving** — dropped tokens are overwritten with spaces, never deleted, and ``gcnew`` becomes ``new`` plus padding — and line breaks inside a removed token are kept, so every offset, l
(source: bytes)
| 3662 | |
| 3663 | |
| 3664 | def _normalize_cpp_cli(source: bytes) -> bytes | None: |
| 3665 | """Rewrite C++/CLI spellings to standard C++ ones, or None if not C++/CLI. |
| 3666 | |
| 3667 | The rewrite is **byte-length preserving** — dropped tokens are overwritten |
| 3668 | with spaces, never deleted, and ``gcnew`` becomes ``new`` plus padding — and |
| 3669 | line breaks inside a removed token are kept, so every offset, line and |
| 3670 | column still points at the same place in the file on disk and reported |
| 3671 | source locations stay accurate (#2876). |
| 3672 | """ |
| 3673 | if not _CPP_CLI_MARKER_RE.search(source): |
| 3674 | return None |
| 3675 | out = _CPP_CLI_CLASS_RE.sub(_blank_keeping_newlines, source) |
| 3676 | out = re.sub(rb"\bgcnew\b", b"new ", out) |
| 3677 | out = _CPP_CLI_SUFFIX_UNAMBIGUOUS_RE.sub(b" ", out) |
| 3678 | out = _CPP_CLI_SUFFIX_DECL_RE.sub(rb"\1 ", out) |
| 3679 | return _CPP_CLI_ATTR_RE.sub(_blank_keeping_newlines, out) |
| 3680 | |
| 3681 | |
| 3682 | _CPP_EXPORT_MACRO_RE = re.compile( |
no outgoing calls