| 584 | |
| 585 | class _CommentSpec: |
| 586 | def __init__(self, full_prefixes, inline_prefixes): |
| 587 | full_patterns = ( |
| 588 | # prefix at the beginning of a line |
| 589 | fr'^({re.escape(prefix)}).*' |
| 590 | for prefix in full_prefixes |
| 591 | ) |
| 592 | inline_patterns = ( |
| 593 | # prefix at the beginning of the line or following a space |
| 594 | fr'(^|\s)({re.escape(prefix)}.*)' |
| 595 | for prefix in inline_prefixes |
| 596 | ) |
| 597 | self.pattern = re.compile('|'.join(itertools.chain(full_patterns, inline_patterns))) |
| 598 | |
| 599 | def strip(self, text): |
| 600 | return self.pattern.sub('', text).rstrip() |