Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
89
Task/URL-encoding/Action-/url-encoding.action
Normal file
89
Task/URL-encoding/Action-/url-encoding.action
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
BYTE FUNC MustEncode(CHAR c CHAR ARRAY ex)
|
||||
BYTE i
|
||||
|
||||
IF c>='a AND c<='z OR c>='A AND c<='Z OR c>='0 AND c<='9 THEN
|
||||
RETURN (0)
|
||||
FI
|
||||
IF ex(0)>0 THEN
|
||||
FOR i=1 TO ex(0)
|
||||
DO
|
||||
IF ex(i)=c THEN
|
||||
RETURN (0)
|
||||
FI
|
||||
OD
|
||||
FI
|
||||
RETURN (1)
|
||||
|
||||
PROC Append(CHAR ARRAY s CHAR c)
|
||||
s(0)==+1
|
||||
s(s(0))=c
|
||||
RETURN
|
||||
|
||||
PROC Encode(CHAR ARRAY in,out,ex BYTE spaceToPlus)
|
||||
CHAR ARRAY hex=['0 '1 '2 '3 '4 '5 '6 '7 '8 '9 'A 'B 'C 'D 'E 'F]
|
||||
BYTE i
|
||||
CHAR c
|
||||
|
||||
out(0)=0
|
||||
FOR i=1 TO in(0)
|
||||
DO
|
||||
c=in(i)
|
||||
IF spaceToPlus=1 AND c=32 THEN
|
||||
Append(out,'+)
|
||||
ELSEIF MustEncode(c,ex) THEN
|
||||
Append(out,'%)
|
||||
Append(out,hex(c RSH 4))
|
||||
Append(out,hex(c&$0F))
|
||||
ELSE
|
||||
Append(out,c)
|
||||
FI
|
||||
OD
|
||||
RETURN
|
||||
|
||||
PROC EncodeRaw(CHAR ARRAY in,out)
|
||||
Encode(in,out,"",0)
|
||||
RETURN
|
||||
|
||||
PROC EncodeRFC3986(CHAR ARRAY in,out)
|
||||
Encode(in,out,"-._~",0)
|
||||
RETURN
|
||||
|
||||
PROC EncodeHTML5(CHAR ARRAY in,out)
|
||||
Encode(in,out,"-._*",1)
|
||||
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)
|
||||
|
||||
EncodeRaw(in,out)
|
||||
PrintInv("encoded ")
|
||||
PrintF(" %S%E",out)
|
||||
|
||||
EncodeRFC3986(in,out)
|
||||
PrintInv("RFC 3986")
|
||||
PrintF(" %S%E",out)
|
||||
|
||||
EncodeHTML5(in,out)
|
||||
PrintInv("HTML 5 ")
|
||||
PrintF(" %S%E%E",out)
|
||||
RETURN
|
||||
|
||||
PROC Main()
|
||||
Test("http://foo bar/")
|
||||
Test("http://www.rosettacode.org/wiki/URL_encoding")
|
||||
Test("http://foo bar/*_-.html")
|
||||
RETURN
|
||||
Loading…
Add table
Add a link
Reference in a new issue