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, nsIUnicodeEncoder* encoder) {  char* inBuf = nsnull; if(encoder) inBuf  = UnicodeToNewBytes(aString.GetUnicode(), aString.Length(), encoder);  if(nsnull == inBuf) 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) {                                     // convert space to +	    *outChar++ = '+';	  } else if ( (((*inChar - '0') >= 0) && (('9' - *inChar) >= 0)) ||   // don't conver alphanumeric                (((*inChar - 'a') >= 0) && (('z' - *inChar) >= 0)) ||   // or '.' or '_'				        (((*inChar - 'A') >= 0) && (('Z' - *inChar) >= 0)) ||                ('.' == *inChar) || ('_' == *inChar)) {	    *outChar++ = *inChar;	  } else {                                                 // convert all else to hex	    *outChar++ = '%';      *outChar++ = toHex[(*inChar >> 4) & 0x0F];      *outChar++ = toHex[*inChar & 0x0F];	  }  }  *outChar = 0;  // terminate the string}