September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
29
Task/URL-encoding/Phix/url-encoding.phix
Normal file
29
Task/URL-encoding/Phix/url-encoding.phix
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
--
|
||||
-- demo\rosetta\encode_url.exw
|
||||
-- ===========================
|
||||
--
|
||||
function nib(integer b)
|
||||
return b+iff(b<=9?'0':'A'-10)
|
||||
end function
|
||||
|
||||
function encode_url(string s, string exclusions="", integer spaceplus=0)
|
||||
string res = ""
|
||||
for i=1 to length(s) do
|
||||
integer ch = s[i]
|
||||
if ch=' ' and spaceplus then
|
||||
ch = '+'
|
||||
elsif not find(ch,exclusions)
|
||||
and (ch<'0'
|
||||
or (ch>'9' and ch<'A')
|
||||
or (ch>'Z' and ch<'a')
|
||||
or ch>'z') then
|
||||
res &= '%'
|
||||
res &= nib(floor(ch/#10))
|
||||
ch = nib(and_bits(ch,#0F))
|
||||
end if
|
||||
res &= ch
|
||||
end for
|
||||
return res
|
||||
end function
|
||||
|
||||
printf(1,"%s\n",{encode_url("http://foo bar/")})
|
||||
Loading…
Add table
Add a link
Reference in a new issue