URLEncode
From Pickwiki
HomePage>>SourceCode>>BasicSource>>URLEncode
This is a function to correctly URLEncode a string.
URL encoding of a character consists of a "%" symbol, followed by the two-digit hexadecimal representation (case-insensitive) of the ISO-Latin code point for the character.
Some of the encoding decisions can get tricky in the 32-47 range and you will have to decide how you might encode sections of strings to override encrypting some potentially valid unencoded URI delimiters.
References:
See http://www.gbiv.com/protocols/uri/rfc/rfc3986.html#characters
See http://www.permadi.com/tutorial/urlEncoding
function URLEncode(inString)
*// perform standard URL encoding for UV ascii. ISO-8859-1 (ISO-Latin) character set.
*// stuart boydell 17-Dec-2004
*// basic example:
*// deffun URLEncode(string) ;* calling *URLEncode ;*[use 'calling globID' if you globally catalogue the program]
*// encodedString = URLEncode(unencodedString)
*// Only alphanumerics [0-9a-zA-Z], the special characters $-_.+!*'(),
*// and reserved characters used for their reserved purposes may be
*// used unencoded within a URL.
*// This process encodes unsafe characters to their URL safe
*// equivalent. eg. char(2) -> "%02"
*// First encodes char(37) "%" to %25 then loops through other ASCII.CODES ranges.
*// ranges of ascii codes of all characters to be encoded
*// 0-31 ASCII Control Characters Unsafe
*// 32-47 Reserved Characters ' '!?#$%&'()*+,-./ Unsafe
*// 48-57 ASCII Characters and Numbers 0-9 Safe
*// 58-64 Reserved Characters :;<=>?@ Unsafe
*// 65-90 ASCII Characters A-Z Safe
*// 91-96 Reserved Characters [\]^_` Unsafe
*// 97-122 ASCII Characters a-z Safe
*// 123-126 Reserved Characters {|}~ Unsafe
*// 127 Control Characters ' ' Unsafe
*// 128-255 Non-ASCII Characters ' ' Unsafe
*// 'Special' encoding characters
equ E.PERCENT to '%',
E.SPACE to ' ',
E.PLUS to '+'
*// 'Normal' encoding start/end characters (decimal ascii)
equ E.ASCII.START to (00:@am:38:@am:47:@am:58:@am:91:@am:96:@am:123),
E.ASCII.END to (36:@am:44:@am:47:@am:64:@am:94:@am:96:@am:255),
E.MAXRANGE to 7
*// convert 'special' encoding characters "%+[sp]"
outString = change(inString,E.PERCENT,E.PERCENT:'25')
*// space may be converted to '+' under some schemes...
*//outString = change(outString,E.PLUS,E.PERCENT:'2B')
*//outString = change(outString,E.SPACE,E.PLUS)
*// now convert 'normal' character ranges
for i = 1 to E.MAXRANGE
for j = E.ASCII.START<i> to E.ASCII.END<i>
jchar = char(j) ;*// get char from decimal val
*// index() character before change() - faster
if index(outString,jchar,1) then
outString = change(outString,jchar,E.PERCENT:dtx(j,2))
end
next j
next i
return(outString)
the:end
HomePage>>SourceCode>>BasicSource>>URLEncode