Compared against declared_pairs · told 11 of 12 deliberately broken copies apart · 2717 ms
def tweak(ch):
if ch == '\n':
return '\n'
if ch == '\r':
return '\r'
if ch == '\t':
return '\t'
if ch == ' ':
return ' '
if ch == '%':
return '%'
if ch == '&':
return '&'
return ch
def solve(s):
out = ''
i = 0
n = len(s)
while i < n:
ch = tweak(s[i])
if ch == '&':
rest = ''
j = i + 1
while j < n and j < i + 6:
rest = rest + tweak(s[j])
j = j + 1
name = ''
step = 0
if rest[:5] == 'quot;':
name = '"'
step = 5
else:
if rest[:5] == 'apos;':
name = "'"
step = 5
else:
if rest[:4] == 'amp;':
name = '&'
step = 4
else:
if rest[:3] == 'lt;':
name = '<'
step = 3
else:
if rest[:3] == 'gt;':
name = '>'
step = 3
else:
if rest[:4] == '#39;':
name = "'"
step = 4
else:
if rest[:4] == '#10;':
name = '\n'
step = 4
else:
if rest[:4] == '#13;':
name = '\r'
step = 4
if step > 0:
out = out + name
i = i + 1 + step
else:
out = out + ch
i = i + 1
else:
out = out + ch
i = i + 1
return out
12 test cases ship with it; the first three:
| in | out |
|---|---|
yjwdhw hlgb yjwdhw fylb 0 | yjwdhw hlgb yjwdhw fylb 0 |
ogt itohl ogt dggs 1 | ogt itohl ogt dggs 1 |
wljtpu uofskg wljtpu jwwfs 2 | wljtpu uofskg wljtpu jwwfs 2 |
GET https://research.zaiba.cloud/api/v1/programs/html_unescape
POST https://research.zaiba.cloud/api/v1/programs/html_unescape/run
{"input": "…"}
# 200 · X-DeAI-Rail: grant (free within the allowance) · output + signed receipt
GET https://research.zaiba.cloud/api/v1/programs/html_unescape/code
# 200 · text/plain · the tool as one Python file, written by the library's authors