URL decoding: Difference between revisions

Added solution for Action!
(Added solution for Action!)
Line 52:
 
WRITE: 'Encoded URL: ', lv_encoded_url, /, 'Decoded URL: ', lv_decoded_url.</lang>
 
=={{header|Action!}}==
<lang Action!>PROC Append(CHAR ARRAY s CHAR c)
s(0)==+1
s(s(0))=c
RETURN
 
CHAR FUNC GetCharFromHex(CHAR c1,c2)
CHAR ARRAY hex=['0 '1 '2 '3 '4 '5 '6 '7 '8 '9 'A 'B 'C 'D 'E 'F]
BYTE i,res
 
res=0
FOR i=0 TO 15
DO
IF c1=hex(i) THEN res==+i LSH 4 FI
IF c2=hex(i) THEN res==+i FI
OD
RETURN (res)
 
PROC Decode(CHAR ARRAY in,out)
BYTE i
CHAR c
 
out(0)=0
i=1
WHILE i<=in(0)
DO
c=in(i)
i==+1
IF c='+ THEN
Append(out,' )
ELSEIF c='% THEN
c=GetCharFromHex(in(i),in(i+1))
i==+2
Append(out,c)
ELSE
Append(out,c)
FI
OD
RETURN
 
PROC PrintInv(CHAR ARRAY a)
BYTE i
 
IF a(0)>0 THEN
FOR i=1 TO a(0)
DO
Put(a(i)%$80)
OD
FI
RETURN
 
PROC Test(CHAR ARRAY in)
CHAR ARRAY out(256)
 
PrintInv("input ")
PrintF(" %S%E",in)
 
Decode(in,out)
PrintInv("decoded")
PrintF(" %S%E%E",out)
RETURN
 
PROC Main()
Test("http%3A%2F%2Ffoo%20bar%2F")
Test("http%3A%2F%2Ffoo+bar%2F*_-.html")
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/URL_decoding.png Screenshot from Atari 8-bit computer]
<pre>
input http%3A%2F%2Ffoo%20bar%2F
decoded http://foo bar/
 
input http%3A%2F%2Ffoo+bar%2F*_-.html
decoded http://foo bar/*_-.html
</pre>
 
=={{header|Ada}}==
Anonymous user