Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
64
Task/URL-encoding/NetRexx/url-encoding.netrexx
Normal file
64
Task/URL-encoding/NetRexx/url-encoding.netrexx
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
testcase()
|
||||
say
|
||||
say 'RFC3986'
|
||||
testcase('RFC3986')
|
||||
say
|
||||
say 'HTML5'
|
||||
testcase('HTML5')
|
||||
say
|
||||
return
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
method encode(url, varn) public static
|
||||
|
||||
variation = varn.upper
|
||||
opts = ''
|
||||
opts['RFC3986'] = '-._~'
|
||||
opts['HTML5'] = '-._*'
|
||||
|
||||
rp = ''
|
||||
loop while url.length > 0
|
||||
parse url tc +1 url
|
||||
select
|
||||
when tc.datatype('A') then do
|
||||
rp = rp || tc
|
||||
end
|
||||
when tc == ' ' then do
|
||||
if variation = 'HTML5' then
|
||||
rp = rp || '+'
|
||||
else
|
||||
rp = rp || '%' || tc.c2x
|
||||
end
|
||||
otherwise do
|
||||
if opts[variation].pos(tc) > 0 then do
|
||||
rp = rp || tc
|
||||
end
|
||||
else do
|
||||
rp = rp || '%' || tc.c2x
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return rp
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
method testcase(variation = '') public static
|
||||
|
||||
url = [ -
|
||||
'http://foo bar/' -
|
||||
, 'mailto:"Ivan Aim" <ivan.aim@email.com>' -
|
||||
, 'mailto:"Irma User" <irma.user@mail.com>' -
|
||||
, 'http://foo.bar.com/~user-name/_subdir/*~.html' -
|
||||
]
|
||||
|
||||
loop i_ = 0 to url.length - 1
|
||||
say url[i_]
|
||||
say encode(url[i_], variation)
|
||||
end i_
|
||||
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue