URLEncode: Difference between revisions
From Pickwiki
Jump to navigationJump to search
mNo edit summary |
mNo edit summary |
||
| Line 1: | Line 1: | ||
HomePage>>SourceCode>>BasicSource>>URLEncode | HomePage>>SourceCode>>BasicSource>><nowiki>URLEncode</nowiki> | ||
This is a function to correctly URLEncode a string.<br> | This is a function to correctly URLEncode a string.<br> | ||
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.<br> | |||
See http://www.permadi.com/tutorial/urlEncoding/ for more info. | |||
<PRE> | <PRE> | ||
function URLEncode( | function URLEncode(inString) | ||
*// perform standard URL encoding for UV ascii. | *// perform standard URL encoding for UV ascii. ISO-8859-1 (ISO-Latin) character set. | ||
*// | *// stuart boydell 17-Dec-2004 | ||
*// deffun URLEncode(string) | *// basic example: | ||
*// deffun URLEncode(string) ;* calling *URLEncode ;*- use this if you globally catalogue the program | |||
*// encodedString = URLEncode(unencodedString) | *// encodedString = URLEncode(unencodedString) | ||
| Line 18: | Line 19: | ||
*// and reserved characters used for their reserved purposes may be | *// and reserved characters used for their reserved purposes may be | ||
*// used unencoded within a URL. | *// 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 | *// ranges of ascii codes of all characters to be encoded | ||
| Line 31: | Line 37: | ||
*// 128-255 Non-ASCII Characters ' ' Unsafe | *// 128-255 Non-ASCII Characters ' ' Unsafe | ||
*// 'Special' encoding characters | |||
equ E.PERCENT to '%', | |||
E. | E.SPACE to ' ', | ||
E. | 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 i = 1 to E.MAXRANGE | ||
for j = | 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 j | ||
next i | next i | ||
return(string) | return(string) | ||
the:end | |||
</PRE> | </PRE> | ||
HomePage>>SourceCode>>BasicSource>><nowiki>URLEncode</nowiki> | |||
Revision as of 01:13, 30 June 2006
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