[PATCH 28/38] docs: kdoc_re: prevent adding whitespaces on sub replacements

Mauro Carvalho Chehab
2026-02-18T10:13:29Z

When NestedMatch is used, blank whitespaces may be placed after
substitutions. As such spaces are part of the C syntax, we can
safelly drop them, improving the quality of the output.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
tools/lib/python/kdoc/kdoc_re.py | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/lib/python/kdoc/kdoc_re.py b/tools/lib/python/kdoc/kdoc_re.py
index e3809aaa0310..44af43aa1e93 100644
--- a/tools/lib/python/kdoc/kdoc_re.py
+++ b/tools/lib/python/kdoc/kdoc_re.py
@@ -344,8 +344,12 @@ class NestedMatch:

cur_pos = 0
n = 0
+ l = len(line)

for start, end, pos in self._search(line):
+ while cur_pos < l and line[cur_pos] == ' ':
+ cur_pos += 1
+
out += line[cur_pos:start]

# Value, ignoring start/end delimiters
@@ -368,7 +372,9 @@ class NestedMatch:
break

# Append the remaining string
- l = len(line)
+ while cur_pos < l and line[cur_pos] == ' ':
+ cur_pos += 1
+
out += line[cur_pos:l]

return out
--
2.52.0