~ruther/qmk_firmware

ref: d16d87c2f33f66e02861a657f259a9c82307de8f qmk_firmware/lib/python/qmk/comment_remover.py -rw-r--r-- 538 bytes
d16d87c2 — Sergey Vlasov Keychron Q11 ISO: Fix left Shift breakage due to a wrong matrix mask (#21655) 1 year, 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""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)
Do not follow this link