01-17-2009 07:11 PM
Also for url encoding: http://www.w3.org/International/URLUTF8Encoder.jav
For url decoding: http://groups.google.com/group/Google-Accounts-API
04-02-2009 05:08 PM
OK that array in that example seems a little much. The % encoding is very simple it is a % followed by the 2 digit hex representation of the byte. So you wouldn't need the array, you would just use:
int i = Integer.parseInt(s);
string hex = Integer.toHexString(i);
if ( hex.length() < 2 )
hex = "0" + hex;
hex = "%" + hex;
You would only really need to do this for characters that fall into the brach of being invalid URL characters http://www.w3schools.com/tags/ref_urlencode.asp.
When I did this a long time ago I did everything outside the a-zA-Z range so I didn't have to do a lot of testing of values.
04-02-2009 10:09 PM - edited 04-02-2009 10:26 PM
That's not going to work for characters outside the range 0x00-0xFF. (For that matter, neither does URLEncodedPostData.) For more general data handling (say, the Euro currency symbol, non-Latin alphabets, etc.), you need something a lot better. According to RFC 3986, the following transformations are required:
characters => UTF-8 octet stream => URI-encoded characters
Decoding does these transformations in the reverse.
The code at w3.org is rather old (RFC 3986 was published in 2005) and isn't exactly correct. For one thing, it assumes that Unicode ends at U+FFFF, which isn't the case these days. It also fails to encode certain characters that are now reserved as subcomponent delimiters by RFC 3986. I recently posted some code in this thread that does the job. It isn't anywhere near as efficient as the W3 code--but as the saying goes, "I'd rather optimize debugged code than debug optimized code.
01-15-2011 01:34 PM
check this link