зеркало из https://github.com/mozilla/gecko-dev.git
better error handling in append method
This commit is contained in:
Родитель
8e3ffd0041
Коммит
dedba98925
|
@ -244,14 +244,29 @@ PRBool nsScanner::Append(nsString& aBuffer) {
|
|||
PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){
|
||||
|
||||
if(mUnicodeDecoder) {
|
||||
PRInt32 unicharLength = 0;
|
||||
PRInt32 unicharBufLen = 0;
|
||||
mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharBufLen);
|
||||
PRUnichar *unichars = new PRUnichar [ unicharBufLen ];
|
||||
nsresult res;
|
||||
do {
|
||||
PRInt32 srcLength = aLen;
|
||||
mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharLength);
|
||||
PRUnichar *unichars = new PRUnichar [ unicharLength ];
|
||||
nsresult res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength );
|
||||
PRInt32 unicharLength = unicharBufLen;
|
||||
res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength );
|
||||
mBuffer.Append(unichars, unicharLength);
|
||||
delete[] unichars;
|
||||
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 unicharBufLen = 0;
|
||||
mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharBufLen);
|
||||
PRUnichar *unichars = new PRUnichar [ unicharBufLen ];
|
||||
nsresult res;
|
||||
do {
|
||||
PRInt32 srcLength = aLen;
|
||||
mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharLength);
|
||||
PRUnichar *unichars = new PRUnichar [ unicharLength ];
|
||||
nsresult res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength );
|
||||
PRInt32 unicharLength = unicharBufLen;
|
||||
res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength );
|
||||
mBuffer.Append(unichars, unicharLength);
|
||||
delete[] unichars;
|
||||
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 {
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче