Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 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
|
||||
28
Task/URL-encoding/REXX/url-encoding-2.rexx
Normal file
28
Task/URL-encoding/REXX/url-encoding-2.rexx
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/*REXX program encodes a URL text, blanks ──► +, preserves -._* and -._~ */
|
||||
url.=; 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'
|
||||
do j=1 while url.j\==''; say
|
||||
say ' original: ' url.j
|
||||
say ' encoded: ' URLencode(url.j)
|
||||
end /*j*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
URLencode: procedure; parse arg $,,z; t1= '-._~' /*get args, null Z.*/
|
||||
skip=0; t2= '-._*'
|
||||
do k=1 for length($); _=substr($, k, 1) /*get a character. */
|
||||
if skip\==0 then do; skip=skip-1 /*skip t1 or t2 ? */
|
||||
iterate /*skip a character.*/
|
||||
end
|
||||
select
|
||||
when datatype(_, 'A') then z=z || _ /*is alphanumeric ?*/
|
||||
when _==' ' then z=z'+' /*is it a blank ?*/
|
||||
when substr($, k, 4)==t1 |, /*is it t1 or t2 ?*/
|
||||
substr($, k, 4)==t2 then do; skip=3 /*skip 3 characters*/
|
||||
z=z || substr($, k, 4)
|
||||
end
|
||||
otherwise z=z'%'c2x(_) /*special character*/
|
||||
end /*select*/
|
||||
end /*k*/
|
||||
return z
|
||||
Loading…
Add table
Add a link
Reference in a new issue