mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 13:55:43 +00:00
Unicode encoder related change for unmapped characters.
If unicode encoder cannot map a character to the target encoding, it returns used unicode length including the unmapped character. That is true for all encoder except ISO-2022-JP (bug #15706). Changed the callers to match the encoder behavior. bug 8865, r=cata.
This commit is contained in:
parent
1486d36542
commit
35df054c4f
@ -183,7 +183,7 @@ nsSaveAsCharset::DoCharsetConversion(const PRUnichar *inString, char **outString
|
||||
dstLength = bufferLength - pos2;
|
||||
rv = mEncoder->Convert(&inString[pos1], &srcLength, &dstPtr[pos2], &dstLength);
|
||||
|
||||
pos1 += srcLength;
|
||||
pos1 += srcLength ? srcLength : 1;
|
||||
pos2 += dstLength;
|
||||
dstPtr[pos2] = '\0';
|
||||
|
||||
@ -200,7 +200,7 @@ nsSaveAsCharset::DoCharsetConversion(const PRUnichar *inString, char **outString
|
||||
|
||||
// do the fallback
|
||||
if (!ATTR_NO_FALLBACK(mAttribute)) {
|
||||
PRUnichar unMappedChar = inString[pos1];
|
||||
PRUnichar unMappedChar = inString[pos1-1];
|
||||
|
||||
rv = mEncoder->GetMaxLength(inString+pos1, inStringLength-pos1, &dstLength);
|
||||
if (NS_FAILED(rv))
|
||||
@ -211,7 +211,6 @@ nsSaveAsCharset::DoCharsetConversion(const PRUnichar *inString, char **outString
|
||||
break;
|
||||
dstPtr[pos2] = '\0';
|
||||
}
|
||||
pos1++; // for the unmapped char
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -90,13 +90,13 @@ nsresult ConvertFromUnicode(const nsString& aCharset,
|
||||
if (0 >= unicharLength || NS_ERROR_UENC_NOMAPPING != res) {
|
||||
break;
|
||||
}
|
||||
// could not map unicode to the destination charset, skip one unichar and continue
|
||||
// increment for source unicode, skip one unichar
|
||||
unichars += unicharLength + 1;
|
||||
oldUnicharLength -= (unicharLength + 1);
|
||||
// could not map unicode to the destination charset
|
||||
// increment for source unicode and continue
|
||||
unichars += unicharLength;
|
||||
oldUnicharLength -= unicharLength; // adjust availabe buffer size
|
||||
unicharLength = oldUnicharLength;
|
||||
// estimate target length again
|
||||
(void) encoder->GetMaxLength(unichars, unicharLength, &dstLength);
|
||||
// reset the encoder
|
||||
encoder->Reset();
|
||||
}
|
||||
(*outCString)[totalCLength] = '\0';
|
||||
}
|
||||
|
@ -1483,7 +1483,6 @@ PRInt32 MimeCharsetConverterClass::Convert(const char* inBuffer, const PRInt32 i
|
||||
else {
|
||||
// convert from unicode
|
||||
PRUnichar *currentUStringPtr = unichars;
|
||||
PRInt32 oldUnicharLength = unicharLength;
|
||||
PRInt32 currentUnicharLength = unicharLength;
|
||||
char *currentCStringPtr = dstPtr;
|
||||
PRInt32 totalCLength = 0;
|
||||
@ -1499,19 +1498,17 @@ PRInt32 MimeCharsetConverterClass::Convert(const char* inBuffer, const PRInt32 i
|
||||
if (0 >= currentUnicharLength || NS_ERROR_UENC_NOMAPPING != res) {
|
||||
break;
|
||||
}
|
||||
// could not map unicode to the destination charset, skip one unichar and continue
|
||||
// increment for source unicode, skip one unichar
|
||||
// could not map unicode to the destination charset
|
||||
// increment for source unicode and continue
|
||||
if (NULL != numUnConverted) {
|
||||
(*numUnConverted)++;
|
||||
}
|
||||
currentUStringPtr += currentUnicharLength + 1;
|
||||
oldUnicharLength -= (currentUnicharLength + 1);
|
||||
currentUnicharLength = oldUnicharLength;
|
||||
// estimate target length again
|
||||
(void) encoder->GetMaxLength(currentUStringPtr, currentUnicharLength, &dstLength);
|
||||
if (dstLength > unicharLength) {
|
||||
dstLength = unicharLength; // not to exceed allocated buffer length
|
||||
}
|
||||
currentUStringPtr += currentUnicharLength;
|
||||
unicharLength -= currentUnicharLength; // adjust availabe buffer size
|
||||
currentUnicharLength = unicharLength;
|
||||
|
||||
// reset the encoder
|
||||
encoder->Reset();
|
||||
}
|
||||
dstPtr[totalCLength] = '\0';
|
||||
*outBuffer = dstPtr; // set the result string
|
||||
|
Loading…
Reference in New Issue
Block a user