Tools: include STRNLEN macros in code_clean utility

This commit is contained in:
Campbell Barton
2025-04-12 13:39:11 +10:00
parent 0fb6cc72fd
commit ac402bf7af

View File

@@ -1154,6 +1154,29 @@ class edit_generators:
content_fail='__ALWAYS_FAIL__',
))
# `BLI_strnlen(a, sizeof(a))` -> `STRNLEN(a)`
# `BLI_strnlen(a, SOME_ID)` -> `STRNLEN(a)`
for src, dst in (
("BLI_strnlen", "STRNLEN"),
("BLI_strnlen_utf8", "STRNLEN_UTF8"),
):
for match in re.finditer(
(r"\b" + src + (
r"\(([^,]+),\s+" r"("
r"sizeof\([^\(\)]+\)" # Trailing `sizeof(..)`.
r"|"
r"[a-zA-Z0-9_]+" # Trailing identifier (typically a define).
r")" r"\)"
)),
data,
flags=re.MULTILINE,
):
edits.append(Edit(
span=match.span(),
content='{:s}({:s})'.format(dst, match.group(1)),
content_fail='__ALWAYS_FAIL__',
))
# `BLI_snprintf(a, SOME_SIZE, ...` -> `SNPRINTF(a, ...`
for src, dst in (
("BLI_snprintf", "SNPRINTF"),