From 65c75fb459622072fbed1315d2f468fc3ee71897 Mon Sep 17 00:00:00 2001 From: "nhotta%netscape.com" Date: Wed, 22 Mar 2000 21:28:08 +0000 Subject: [PATCH] For unicode conversion, changed to call encode->Finish(), use set output behavior to avoid internal loop, r=cata. --- mailnews/mime/src/comi18n.cpp | 41 ++++++++++------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/mailnews/mime/src/comi18n.cpp b/mailnews/mime/src/comi18n.cpp index 966be7127d7a..5e8ad8b3f98a 100644 --- a/mailnews/mime/src/comi18n.cpp +++ b/mailnews/mime/src/comi18n.cpp @@ -1416,37 +1416,20 @@ PRInt32 MimeCharsetConverterClass::Convert(const char* inBuffer, const PRInt32 i } else { // convert from unicode - PRUnichar *currentUStringPtr = unichars; - PRInt32 currentUnicharLength = unicharLength; - char *currentCStringPtr = dstPtr; - PRInt32 totalCLength = 0; - while (1) { - res = encoder->Convert(currentUStringPtr, ¤tUnicharLength, currentCStringPtr, &dstLength); - - // increment for destination - currentCStringPtr += dstLength; - totalCLength += dstLength; - - // break: this is usually the case - // source length <= zero and no error or unrecoverable error - if (0 >= currentUnicharLength || NS_ERROR_UENC_NOMAPPING != res) { - break; + res = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?'); + if (NS_SUCCEEDED(res)) { + res = encoder->Convert(unichars, &unicharLength, dstPtr, &dstLength); + if (NS_SUCCEEDED(res)) { + PRInt32 finLen; + res = encoder->Finish((char *)(*dstPtr+dstLength), &finLen); + if (NS_SUCCEEDED(res)) { + dstLength += finLen; + } + dstPtr[dstLength] = '\0'; + *outBuffer = dstPtr; // set the result string + *outLength = dstLength; } - // could not map unicode to the destination charset - // increment for source unicode and continue - if (NULL != numUnConverted) { - (*numUnConverted)++; - } - currentUStringPtr += currentUnicharLength; - unicharLength -= currentUnicharLength; // adjust availabe buffer size - currentUnicharLength = unicharLength; - - // reset the encoder - encoder->Reset(); } - dstPtr[totalCLength] = '\0'; - *outBuffer = dstPtr; // set the result string - *outLength = totalCLength; } } delete [] unichars;