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


code Text=12;
string 0;               \use zero-terminated strings
 
func Decode(S0);        \Decode URL string and return its address
char S0;
char S1(80);            \BEWARE: very temporary string space returned
int  C, N, I, J;
[I:= 0;  J:= 0;
repeat  C:= S0(I);  I:= I+1;                    \get char
        if C=^% then                            \convert hex to char
                [C:= S0(I);  I:= I+1;
                if C>=^a then C:= C & ~$20;     \convert to uppercase
                N:= C - (if C<=^9 then ^0 else ^A-10);
                C:= S0(I);  I:= I+1;
                if C>=^a then C:= C & ~$20;
                C:= N*16 + C - (if C<=^9 then ^0 else ^A-10);
                ];
        S1(J):= C;  J:= J+1;                    \put char in output string
until   C=0;
return S1;
];
 
Text(0, Decode("http%3A%2F%2Ffoo%20bar%2f"))