rv = aEncoder->Reset(); if (NS_FAILED(rv)) { return nsnull; }  PRInt32 maxByteLen = 0; rv = aEncoder->GetMaxLength(aSrc, (PRInt32)aLen, &maxByteLen); if (NS_FAILED(rv)) { return nsnull; }  res = new char[maxByteLen+1]; if (res) { PRInt32 reslen = maxByteLen; PRInt32 reslen2; PRInt32 srclen = aLen; aEncoder->Convert(aSrc, &srclen, res, &reslen); reslen2 = maxByteLen - reslen; aEncoder->Finish(res + reslen, &reslen2); res[reslen+reslen2] = '\0'; }
if(aSrc && aSrc[0]) { rv = aEncoder->Convert(aSrc, &res); NS_ASSERTION(NS_SUCCEEDED(rv), "conversion failed"); } if(! res) res = nsCRT::strdup("");
nsFormSubmission::UnicodeToNewBytes(const PRUnichar* aSrc, PRUint32 aLen,                                    nsIUnicodeEncoder* aEncoder){  nsresult rv = NS_OK;#ifdef IBMBIDI  PRUint8 ctrlsModAtSubmit = GET_BIDI_OPTION_CONTROLSTEXTMODE(mBidiOptions);  PRUint8 textDirAtSubmit = GET_BIDI_OPTION_DIRECTION(mBidiOptions);  //ahmed 15-1  nsAutoString temp;  nsAutoString newBuffer;  //This condition handle the RTL,LTR for a logical file  if (ctrlsModAtSubmit == IBMBIDI_CONTROLSTEXTMODE_VISUAL     && mCharset.Equals(NS_LITERAL_STRING("windows-1256"),                nsCaseInsensitiveStringComparator())) {    Conv_06_FE_WithReverse(nsString(aSrc),                           newBuffer,                           textDirAtSubmit);    aSrc = (PRUnichar*)newBuffer.get();    aLen=newBuffer.Length();  }  else if (ctrlsModAtSubmit == IBMBIDI_CONTROLSTEXTMODE_LOGICAL          && mCharset.Equals(NS_LITERAL_STRING("IBM864"),                             nsCaseInsensitiveStringComparator())) {    //For 864 file, When it is logical, if LTR then only convert    //If RTL will mak a reverse for the buffer    Conv_FE_06(nsString(aSrc), newBuffer);    aSrc = (PRUnichar*)newBuffer.get();    temp = newBuffer;    aLen=newBuffer.Length();    if (textDirAtSubmit == 2) { //RTL    //Now we need to reverse the Buffer, it is by searching the buffer      PRUint32 loop = aLen;      PRUint32 z;      for (z=0; z<=aLen; z++) {        temp.SetCharAt((PRUnichar)aSrc[loop], z);        loop--;      }    }    aSrc = (PRUnichar*)temp.get();  }  else if (ctrlsModAtSubmit == IBMBIDI_CONTROLSTEXTMODE_VISUAL          && mCharset.Equals(NS_LITERAL_STRING("IBM864"),                             nsCaseInsensitiveStringComparator())                  && textDirAtSubmit == IBMBIDI_TEXTDIRECTION_RTL) {    Conv_FE_06(nsString(aSrc), newBuffer);    aSrc = (PRUnichar*)newBuffer.get();    temp = newBuffer;    aLen=newBuffer.Length();    //Now we need to reverse the Buffer, it is by searching the buffer    PRUint32 loop = aLen;    PRUint32 z;    for (z=0; z<=aLen; z++) {      temp.SetCharAt((PRUnichar)aSrc[loop], z);      loop--;    }    aSrc = (PRUnichar*)temp.get();  }#endif  char* res = nsnull;  rv = aEncoder->Reset();  if (NS_FAILED(rv)) {    return nsnull;  }  PRInt32 maxByteLen = 0;  rv = aEncoder->GetMaxLength(aSrc, (PRInt32)aLen, &maxByteLen);  if (NS_FAILED(rv)) {    return nsnull;  }  res = new char[maxByteLen+1];  if (res) {    PRInt32 reslen = maxByteLen;    PRInt32 reslen2;    PRInt32 srclen = aLen;    aEncoder->Convert(aSrc, &srclen, res, &reslen);    reslen2 = maxByteLen - reslen;    aEncoder->Finish(res + reslen, &reslen2);    res[reslen+reslen2] = '\0';  }  return res;}