September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
33
Task/URL-decoding/Phix/url-decoding.phix
Normal file
33
Task/URL-decoding/Phix/url-decoding.phix
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
--
|
||||
-- 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")})
|
||||
Loading…
Add table
Add a link
Reference in a new issue