logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

comment_remover.py (538B)


  1. """Removes C/C++ style comments from text.
  2. Gratefully adapted from https://stackoverflow.com/a/241506
  3. """
  4. import re
  5. comment_pattern = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE)
  6. def _comment_stripper(match):
  7. """Removes C/C++ style comments from a regex match.
  8. """
  9. s = match.group(0)
  10. return ' ' if s.startswith('/') else s
  11. def comment_remover(text):
  12. """Remove C/C++ style comments from text.
  13. """
  14. return re.sub(comment_pattern, _comment_stripper, text)