all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
72
Task/URL-encoding/REXX/url-encoding-1.rexx
Normal file
72
Task/URL-encoding/REXX/url-encoding-1.rexx
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/* Rexx */
|
||||
do
|
||||
call testcase
|
||||
say
|
||||
say RFC3986
|
||||
call testcase RFC3986
|
||||
say
|
||||
say HTML5
|
||||
call testcase HTML5
|
||||
say
|
||||
return
|
||||
end
|
||||
exit
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
encode:
|
||||
procedure
|
||||
do
|
||||
parse arg url, varn .
|
||||
parse upper var varn variation
|
||||
drop RFC3986 HTML5
|
||||
opts. = ''
|
||||
opts.RFC3986 = '-._~'
|
||||
opts.HTML5 = '-._*'
|
||||
|
||||
rp = ''
|
||||
do while length(url) > 0
|
||||
parse var url tc +1 url
|
||||
select
|
||||
when datatype(tc, 'A') then do
|
||||
rp = rp || tc
|
||||
end
|
||||
when tc == ' ' then do
|
||||
if variation = HTML5 then
|
||||
rp = rp || '+'
|
||||
else
|
||||
rp = rp || '%' || c2x(tc)
|
||||
end
|
||||
otherwise do
|
||||
if pos(tc, opts.variation) > 0 then do
|
||||
rp = rp || tc
|
||||
end
|
||||
else do
|
||||
rp = rp || '%' || c2x(tc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return rp
|
||||
end
|
||||
exit
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
testcase:
|
||||
procedure
|
||||
do
|
||||
parse arg variation
|
||||
X = 0
|
||||
url. = ''
|
||||
X = X + 1; url.0 = X; url.X = 'http://foo bar/'
|
||||
X = X + 1; url.0 = X; url.X = 'mailto:"Ivan Aim" <ivan.aim@email.com>'
|
||||
X = X + 1; url.0 = X; url.X = 'mailto:"Irma User" <irma.user@mail.com>'
|
||||
X = X + 1; url.0 = X; url.X = 'http://foo.bar.com/~user-name/_subdir/*~.html'
|
||||
|
||||
do i_ = 1 to url.0
|
||||
say url.i_
|
||||
say encode(url.i_, variation)
|
||||
end i_
|
||||
|
||||
return
|
||||
end
|
||||
31
Task/URL-encoding/REXX/url-encoding-2.rexx
Normal file
31
Task/URL-encoding/REXX/url-encoding-2.rexx
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*REXX pgm encodes an URL text, blanks──►+, preserves -._* and -._~ */
|
||||
url.1= 'http://foo bar/'
|
||||
url.2= 'mailto:"Ivan Aim" <ivan.aim@email.com>'
|
||||
url.3= 'mailto:"Irma User" <irma.user@mail.com>'
|
||||
url.4= 'http://foo.bar.com/~user-name/_subdir/*~.html'
|
||||
URLs=4
|
||||
do j=1 for URLs; say
|
||||
say url.j
|
||||
say URLencode(url.j)
|
||||
end /*j*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────URENCODE subroutine─────────────────*/
|
||||
URLencode: procedure; parse arg yyy; t1= '-._~' ; skip=0
|
||||
t2= '-._*' ; z=''
|
||||
|
||||
do k=1 for length(yyy); _=substr(yyy,k,1) /*pickoff 1char*/
|
||||
if skip\==0 then do /*skip t1 | t2?*/
|
||||
skip=skip-1 /*skip a char. */
|
||||
iterate
|
||||
end
|
||||
select
|
||||
when datatype(_,'A') then z=z || _ /*alphanumeric?*/
|
||||
when _==' ' then z=z'+' /*is a blank ? */
|
||||
when substr(yyy,k,4)==t1 |, /*t1 or t2 ? */
|
||||
substr(yyy,k,4)==t2 then do; skip=3 /*skip 3 chars.*/
|
||||
z=z || substr(yyy,k,4)
|
||||
end
|
||||
otherwise z=z'%'c2x(_) /*special char.*/
|
||||
end /*select*/
|
||||
end /*k*/
|
||||
return z
|
||||
Loading…
Add table
Add a link
Reference in a new issue