/* 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" ' - , 'mailto:"Irma User" ' - , '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