Strip C/C++ comments from content while preserving line structure. Args: content: The content to strip comments from Returns: Content with comments removed, preserving line numbers
(content: str)
| 29 | |
| 30 | |
| 31 | def strip_comments(content: str) -> str: |
| 32 | """ |
| 33 | Strip C/C++ comments from content while preserving line structure. |
| 34 | |
| 35 | Args: |
| 36 | content: The content to strip comments from |
| 37 | |
| 38 | Returns: |
| 39 | Content with comments removed, preserving line numbers |
| 40 | """ |
| 41 | # Remove multi-line comments (/* ... */) while retaining line numbers. |
| 42 | content = re.sub( |
| 43 | r"/\*.*?\*/", |
| 44 | lambda match: "\n" * match.group(0).count("\n"), |
| 45 | content, |
| 46 | flags=re.DOTALL, |
| 47 | ) |
| 48 | # Remove single-line comments (// ...) |
| 49 | content = re.sub(r"//.*$", "", content, flags=re.MULTILINE) |
| 50 | return content |
| 51 | |
| 52 | |
| 53 | class LoggingInIramChecker(FileContentChecker): |
no test coverage detected