Created
June 29, 2021 10:14
-
-
Save pavel-kirienko/4d4893601d5babe9b71418df1c2d09e9 to your computer and use it in GitHub Desktop.
Transform C-style comments into C++-style comments preserving Doxygen notation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Bulk usage: | |
# find . -name '*.[ch]pp' -exec bash -c 'recomment.py < "{}" > "{}.out" ; mv "{}.out" "{}"' \; | |
import sys, re | |
RE_REPLACE = re.compile(r"(?m)^(\s*?) ?\*(.*)") | |
def replace_one(match) -> str: | |
use_doc = bool(match[1]) | |
sub = r"\1///\2" if use_doc else r"\1//\2" | |
return RE_REPLACE.sub(sub, match[2]) | |
sys.stdout.write(re.sub(r"(?sm)/\*(\**)\s*(.*?)\s*\*/", replace_one, sys.stdin.read())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment