23 lines
565 B
Plaintext
23 lines
565 B
Plaintext
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
|