From 1466fa22c2334dabd78956b353f7352982ac66b6 Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Fri, 1 Jul 2022 23:17:44 +0200 Subject: [PATCH] generate_packets.py: Don't indent preprocessor directives or blank lines See osdn#44976 Signed-off-by: Alina Lenk --- common/generate_packets.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common/generate_packets.py b/common/generate_packets.py index e87bdb2418..fb51ab235a 100755 --- a/common/generate_packets.py +++ b/common/generate_packets.py @@ -265,9 +265,14 @@ def powerset(iterable: typing.Iterable[T_co]) -> "typing.Iterator[tuple[T_co, .. s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) +# matches the beginning of a line followed by neither a # nor the line end, +# i.e. the beginning of any nonempty line that doesn't start with # +INSERT_PREFIX_PATTERN = re.compile(r"^(?!#|$)", re.MULTILINE) + def prefix(prefix: str, text: str) -> str: - """Prepend prefix to every line of text""" - return "\n".join(prefix + line for line in text.split("\n")) + """Prepend prefix to every line of text, except blank lines and those + starting with #""" + return INSERT_PREFIX_PATTERN.sub(prefix, text) # matches an entire field definition line (type, fields and flag info) -- 2.34.1