Skip to content

Instantly share code, notes, and snippets.

@pavel-kirienko
Created June 29, 2021 10:14
Show Gist options
  • Save pavel-kirienko/4d4893601d5babe9b71418df1c2d09e9 to your computer and use it in GitHub Desktop.
Save pavel-kirienko/4d4893601d5babe9b71418df1c2d09e9 to your computer and use it in GitHub Desktop.
Transform C-style comments into C++-style comments preserving Doxygen notation
#!/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