This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function
or mechanism to convert an URL-encoded string into its original unencoded form.



Test cases

   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".
   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".


--
-- demo\rosetta\decode_url.exw
-- ===========================
--
with javascript_semantics
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")})

{} = wait_key()
