From 0bb4d6862a7f176679b22939e1682de177e682a0 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 2 Dec 2024 16:47:31 +0100 Subject: [PATCH] fixup! feat: provide escaped version of `PRODUCT_DIR_ABS` Co-authored-by: Christian Clauss --- pylib/gyp/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pylib/gyp/__init__.py b/pylib/gyp/__init__.py index 84bc141..1cf3d68 100755 --- a/pylib/gyp/__init__.py +++ b/pylib/gyp/__init__.py @@ -24,13 +24,14 @@ DEBUG_VARIABLES = "variables" DEBUG_INCLUDES = "includes" -def EscapeForCString(string): +def EscapeForCString(string: bytes | str) -> str: if isinstance(string, str): string = string.encode(encoding='utf8') - result = '' + backslash_or_double_quote = {ord('\\'), ord('"')} + result = [] for char in string: - if not (32 <= char < 127) or char in (ord('\\'), ord('"')): + if char in backslash_or_double_quote or not 32 <= char < 127: result += '\\%03o' % char else: result += chr(char)