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.
See http://www.permadi.com/tutorial/urlEncoding/ for more info.
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 this 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 These characters are not printable 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:34:@am:38:@am:47:@am:58:@am:91:@am:96:@am:123), E.ASCII.END to (31:@am:36:@am:38:@am:47:@am:64:@am:94:@am:96:@am:255), E.MAXRANGE to 8 *// convert 'special' encoding characters "%+[sp]" string = change(inString,E.PERCENT,E.PERCENT:'25') string = change(string,E.PLUS,E.PERCENT:'2B') string = change(string,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(string,jchar,1) then string = change(string,jchar,E.PERCENT:dtx(j,2)) end next j next i return(string) the:end
HomePage>>SourceCode>>BasicSource>>URLEncode