MCPcopy Create free account
hub / github.com/bytedance/bolt / unquote_string

Function unquote_string

scripts/normalize_blog_posts.py:85–111  ·  view source on GitHub ↗
(value: str)

Source from the content-addressed store, hash-verified

83
84
85def 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
114def is_empty(value: str | None) -> bool:

Callers 2

is_emptyFunction · 0.85
quote_stringFunction · 0.85

Calls 4

lenFunction · 0.85
replaceMethod · 0.80
appendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected