better error handling in append method

This commit is contained in:
ftang%netscape.com 1999-05-04 20:01:55 +00:00
Родитель 8e3ffd0041
Коммит dedba98925
2 изменённых файлов: 46 добавлений и 16 удалений

Просмотреть файл

@ -244,14 +244,29 @@ PRBool nsScanner::Append(nsString& aBuffer) {
PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){
if(mUnicodeDecoder) {
PRInt32 unicharLength = 0;
PRInt32 srcLength = aLen;
mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharLength);
PRUnichar *unichars = new PRUnichar [ unicharLength ];
nsresult res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength );
mBuffer.Append(unichars, unicharLength);
delete[] unichars;
mTotalRead += unicharLength;
PRInt32 unicharBufLen = 0;
mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharBufLen);
PRUnichar *unichars = new PRUnichar [ unicharBufLen ];
nsresult res;
do {
PRInt32 srcLength = aLen;
PRInt32 unicharLength = unicharBufLen;
res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength );
mBuffer.Append(unichars, unicharLength);
mTotalRead += unicharLength;
// if we failed, we consume one byte by replace it with U+FFFD
// and try conversion again.
if(NS_FAILED(res)) {
mBuffer.Append( (PRUnichar)0xFFFD);
mTotalRead++;
aBuffer += srcLength + 1;
aLen -= srcLength + 1;
}
} while (NS_FAILED(res) && (aLen > 0));
// we continue convert the bytes data into Unicode
// if we have conversion error and we have more data.
delete[] unichars;
}
else {

Просмотреть файл

@ -244,14 +244,29 @@ PRBool nsScanner::Append(nsString& aBuffer) {
PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){
if(mUnicodeDecoder) {
PRInt32 unicharLength = 0;
PRInt32 srcLength = aLen;
mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharLength);
PRUnichar *unichars = new PRUnichar [ unicharLength ];
nsresult res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength );
mBuffer.Append(unichars, unicharLength);
delete[] unichars;
mTotalRead += unicharLength;
PRInt32 unicharBufLen = 0;
mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharBufLen);
PRUnichar *unichars = new PRUnichar [ unicharBufLen ];
nsresult res;
do {
PRInt32 srcLength = aLen;
PRInt32 unicharLength = unicharBufLen;
res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength );
mBuffer.Append(unichars, unicharLength);
mTotalRead += unicharLength;
// if we failed, we consume one byte by replace it with U+FFFD
// and try conversion again.
if(NS_FAILED(res)) {
mBuffer.Append( (PRUnichar)0xFFFD);
mTotalRead++;
aBuffer += srcLength + 1;
aLen -= srcLength + 1;
}
} while (NS_FAILED(res) && (aLen > 0));
// we continue convert the bytes data into Unicode
// if we have conversion error and we have more data.
delete[] unichars;
}
else {