nsString* URLEncode(nsString& aString) { char* inBuf  = aString.ToNewCString(); char* outBuf = new char[ (strlen(inBuf) * 3) + 1 ]; URLEncode(inBuf, outBuf); nsString* result = new nsString(outBuf); delete [] outBuf; delete [] inBuf; return result;
void URLEncode(char* aInString, char* aOutString) { if (nsnull == aInString) { return; } static char *toHex = "0123456789ABCDEF"; char* outChar = aOutString; for (char* inChar = aInString; *inChar; inChar++) { if(' ' == *inChar) { *outChar++ = '+'; } else if ( (((*inChar - '0') >= 0) && (('9' - *inChar) >= 0)) || (((*inChar - 'a') >= 0) && (('z' - *inChar) >= 0)) || (((*inChar - 'A') >= 0) && (('Z' - *inChar) >= 0)) || ('.' == *inChar) || ('_' == *inChar)) { *outChar++ = *inChar; } else { *outChar++ = '%'; *outChar++ = toHex[(*inChar >> 4) & 0x0F]; *outChar++ = toHex[*inChar & 0x0F]; } } *outChar = 0;
nsString* URLEncode(nsString& aString) {    char* inBuf  = aString.ToNewCString();	char* outBuf = new char[ (strlen(inBuf) * 3) + 1 ];	URLEncode(inBuf, outBuf);	nsString* result = new nsString(outBuf);	delete [] outBuf;	delete [] inBuf;	return result;}