fix bug 10109
git-svn-id: svn://10.0.0.236/trunk@40077 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -551,6 +551,7 @@ nsresult nsHTMLTokenizer::ConsumeEntity(PRUnichar aChar,CToken*& aToken,nsScanne
|
||||
//convert it into a text token.
|
||||
nsAutoString temp("&");
|
||||
temp.Append(theStr);
|
||||
temp.Append(';');
|
||||
CToken* theToken=theRecycler->CreateTokenOfType(eToken_text,eHTMLTag_text,temp);
|
||||
theRecycler->RecycleToken(aToken);
|
||||
aToken=theToken;
|
||||
|
||||
@@ -243,27 +243,17 @@ PRBool nsScanner::Append(nsString& aBuffer) {
|
||||
*/
|
||||
PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){
|
||||
|
||||
/*************************** SUBTLETY ALERT!! ************************
|
||||
The following block of code converts aBuffer into unicode.
|
||||
The subtlty is that we do it "in-place" on the underlying mBuffer.
|
||||
This is so that we can avoid unnecessary copying of buffer data.
|
||||
*********************************************************************/
|
||||
|
||||
if(mUnicodeDecoder) {
|
||||
PRInt32 unicharBufLen = 0;
|
||||
mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharBufLen);
|
||||
mBuffer.SetCapacity(mBuffer.mLength+unicharBufLen);
|
||||
PRUnichar *unichars = (PRUnichar*)mBuffer.GetUnicode();
|
||||
unichars+=mBuffer.mLength;
|
||||
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 );
|
||||
unichars[mBuffer.mLength+unicharLength]=0; //add this since the unicode converters can't be trusted to do so.
|
||||
mBuffer.mLength+=unicharLength;
|
||||
// mBuffer.Append(unichars, unicharLength);
|
||||
|
||||
unichars[unicharLength]=0; //add this since the unicode converters can't be trusted to do so.
|
||||
mBuffer.Append(unichars, unicharLength);
|
||||
mTotalRead += unicharLength;
|
||||
// if we failed, we consume one byte by replace it with U+FFFD
|
||||
// and try conversion again.
|
||||
@@ -277,14 +267,14 @@ PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){
|
||||
srcLength++;
|
||||
aBuffer += srcLength;
|
||||
aLen -= srcLength;
|
||||
} //if
|
||||
}
|
||||
} 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;
|
||||
delete[] unichars;
|
||||
}
|
||||
else {
|
||||
else {
|
||||
mBuffer.Append(aBuffer,aLen);
|
||||
mTotalRead+=aLen;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user