34 lines
884 B
Plaintext
34 lines
884 B
Plaintext
--
|
|
-- demo\rosetta\decode_url.exw
|
|
-- ===========================
|
|
--
|
|
function decode_url(string s)
|
|
integer skip = 0
|
|
string res = ""
|
|
for i=1 to length(s) do
|
|
if skip then
|
|
skip -= 1
|
|
else
|
|
integer ch = s[i]
|
|
if ch='%' then
|
|
sequence scanres = {}
|
|
if i+2<=length(s) then
|
|
scanres = scanf("#"&s[i+1..i+2],"%x")
|
|
end if
|
|
if length(scanres)!=1 then
|
|
return "decode error"
|
|
end if
|
|
skip = 2
|
|
ch = scanres[1][1]
|
|
elsif ch='+' then
|
|
ch = ' '
|
|
end if
|
|
res &= ch
|
|
end if
|
|
end for
|
|
return res
|
|
end function
|
|
|
|
printf(1,"%s\n",{decode_url("http%3A%2F%2Ffoo%20bar%2F")})
|
|
printf(1,"%s\n",{decode_url("google.com/search?q=%60Abdu%27l-Bah%C3%A1")})
|