mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-12-21 17:13:22 +00:00
751316c344
You can now use `qmk info` to get information about keyboards and keymaps. Co-authored-by: Erovia <Erovia@users.noreply.github.com>
21 lines
538 B
Python
21 lines
538 B
Python
"""Removes C/C++ style comments from text.
|
|
|
|
Gratefully adapted from https://stackoverflow.com/a/241506
|
|
"""
|
|
import re
|
|
|
|
comment_pattern = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE)
|
|
|
|
|
|
def _comment_stripper(match):
|
|
"""Removes C/C++ style comments from a regex match.
|
|
"""
|
|
s = match.group(0)
|
|
return ' ' if s.startswith('/') else s
|
|
|
|
|
|
def comment_remover(text):
|
|
"""Remove C/C++ style comments from text.
|
|
"""
|
|
return re.sub(comment_pattern, _comment_stripper, text)
|