Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
33
Task/URL-encoding/ALGOL-68/url-encoding.alg
Normal file
33
Task/URL-encoding/ALGOL-68/url-encoding.alg
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
BEGIN
|
||||
# encodes the specified url - 0-9, A-Z and a-z are unchanged, #
|
||||
# everything else is converted to %xx where xx are hex-digits #
|
||||
PROC encode url = ( STRING url )STRING:
|
||||
IF url = "" THEN "" # empty string #
|
||||
ELSE
|
||||
# non-empty string #
|
||||
# ensure result will be big enough for a string of all encodable #
|
||||
# characters #
|
||||
STRING hex digits = "0123456789ABCDEF";
|
||||
[ 1 : ( ( UPB url - LWB url ) + 1 ) * 3 ]CHAR result;
|
||||
INT r pos := 0;
|
||||
FOR u pos FROM LWB url TO UPB url DO
|
||||
CHAR c = url[ u pos ];
|
||||
IF ( c >= "0" AND c <= "9" )
|
||||
OR ( c >= "A" AND c <= "Z" )
|
||||
OR ( c >= "a" AND c <= "z" )
|
||||
THEN
|
||||
# no need to encode this character #
|
||||
result[ r pos +:= 1 ] := c
|
||||
ELSE
|
||||
# must encode #
|
||||
INT c code = ABS c;
|
||||
result[ r pos +:= 1 ] := "%";
|
||||
result[ r pos +:= 1 ] := hex digits[ ( c code OVER 16 ) + 1 ];
|
||||
result[ r pos +:= 1 ] := hex digits[ ( c code MOD 16 ) + 1 ]
|
||||
FI
|
||||
OD;
|
||||
result[ 1 : r pos ]
|
||||
FI; # encode url #
|
||||
# task test case #
|
||||
print( ( encode url( "http://foo bar/" ), newline ) )
|
||||
END
|
||||
Loading…
Add table
Add a link
Reference in a new issue