From ac402bf7af9430672429853521bd597b3566cd9f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 12 Apr 2025 13:39:11 +1000 Subject: [PATCH] Tools: include STRNLEN macros in code_clean utility --- tools/utils_maintenance/code_clean.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/utils_maintenance/code_clean.py b/tools/utils_maintenance/code_clean.py index 83f888c4e7e..295824fff1b 100755 --- a/tools/utils_maintenance/code_clean.py +++ b/tools/utils_maintenance/code_clean.py @@ -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"),