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á".


link hexcvt
 
procedure main()
ue := "http%3A%2F%2Ffoo%20bar%2F"
ud := decodeURL(ue) | stop("Improperly encoded string ",image(ue))
write("encoded = ",image(ue)) 
write("decoded = ",image(ue))
end
 
procedure decodeURL(s)              #: decode URL/URI encoded data
static de
initial {                           # build lookup table for everything
  de := table()
  every de[hexstring(ord(c := !string(&ascii)),2)] := c
  }
 
c := ""
s ? until pos(0) do                 # decode every %xx or fail
   c ||:= if ="%" then \de[move(2)] | fail
   else move(1)
return c
end