RosettaCodeData/Task/URL-decoding/XPL0/url-decoding.xpl0

24 lines
846 B
Plaintext

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"))