Escape special characters in a string for TOON encoding. Args: value: String to escape Returns: Escaped string
(value: str)
| 53 | |
| 54 | |
| 55 | def escape_string(value: str) -> str: |
| 56 | """ |
| 57 | Escape special characters in a string for TOON encoding. |
| 58 | |
| 59 | Args: |
| 60 | value: String to escape |
| 61 | |
| 62 | Returns: |
| 63 | Escaped string |
| 64 | """ |
| 65 | # Escape backslashes first |
| 66 | value = value.replace(BACKSLASH, BACKSLASH + BACKSLASH) |
| 67 | # Escape quotes |
| 68 | value = value.replace(QUOTE, BACKSLASH + QUOTE) |
| 69 | # Escape newlines |
| 70 | value = value.replace(NEWLINE, BACKSLASH + 'n') |
| 71 | # Escape tabs |
| 72 | value = value.replace('\t', BACKSLASH + 't') |
| 73 | # Escape carriage returns |
| 74 | value = value.replace('\r', BACKSLASH + 'r') |
| 75 | return value |
| 76 | |
| 77 | |
| 78 | def unescape_string(value: str) -> str: |
no outgoing calls
no test coverage detected
searching dependent graphs…