| 83 | |
| 84 | |
| 85 | def unquote_string(value: str) -> str: |
| 86 | if len(value) < 2 or value[0] != value[-1] or value[0] not in {'"', "'"}: |
| 87 | return value |
| 88 | |
| 89 | unquoted = value[1:-1] |
| 90 | if value[0] == "'": |
| 91 | return unquoted.replace("''", "'") |
| 92 | |
| 93 | escapes = { |
| 94 | '"': '"', |
| 95 | "\\": "\\", |
| 96 | "n": "\n", |
| 97 | "r": "\r", |
| 98 | "t": "\t", |
| 99 | } |
| 100 | decoded: list[str] = [] |
| 101 | index = 0 |
| 102 | while index < len(unquoted): |
| 103 | char = unquoted[index] |
| 104 | if char == "\\" and index + 1 < len(unquoted): |
| 105 | escaped = unquoted[index + 1] |
| 106 | decoded.append(escapes.get(escaped, char + escaped)) |
| 107 | index += 2 |
| 108 | continue |
| 109 | decoded.append(char) |
| 110 | index += 1 |
| 111 | return "".join(decoded) |
| 112 | |
| 113 | |
| 114 | def is_empty(value: str | None) -> bool: |