Skip to content

Commit

Permalink
fixup! feat: provide escaped version of PRODUCT_DIR_ABS
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Clauss <[email protected]>
  • Loading branch information
addaleax and cclauss authored Dec 2, 2024
1 parent 117f80e commit 0bb4d68
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pylib/gyp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0bb4d68

Please sign in to comment.