(string: bytes | str)
| 28 | |
| 29 | |
| 30 | def EscapeForCString(string: bytes | str) -> str: |
| 31 | if isinstance(string, str): |
| 32 | string = string.encode(encoding="utf8") |
| 33 | |
| 34 | backslash_or_double_quote = {ord("\\"), ord('"')} |
| 35 | result = "" |
| 36 | for char in string: |
| 37 | if char in backslash_or_double_quote or not 32 <= char < 127: |
| 38 | result += "\\%03o" % char |
| 39 | else: |
| 40 | result += chr(char) |
| 41 | return result |
| 42 | |
| 43 | |
| 44 | def DebugOutput(mode, message, *args): |