зеркало из https://github.com/mozilla/pjs.git
Fix for bug 4463. Expat now accepts unicode buffers.
This commit is contained in:
Родитель
6e5d4b7e87
Коммит
2c9af25208
|
@ -27,11 +27,8 @@
|
|||
#include "nsScanner.h"
|
||||
#include "nsDTDUtils.h"
|
||||
#include "nsParserError.h"
|
||||
// #include "nsParser.h"
|
||||
#include "nsIParser.h"
|
||||
#include "prlog.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/************************************************************************
|
||||
And now for the main class -- nsExpatTokenizer...
|
||||
|
@ -134,10 +131,14 @@ nsExpatTokenizer::nsExpatTokenizer() : nsHTMLTokenizer() {
|
|||
NS_INIT_REFCNT();
|
||||
mBytesParsed = 0;
|
||||
mSeenError = PR_FALSE;
|
||||
mExpatParser = XML_ParserCreate(NULL);
|
||||
gTokenRecycler=(CTokenRecycler*)GetTokenRecycler();
|
||||
if (mExpatParser) {
|
||||
SetupExpatCallbacks();
|
||||
nsAutoString buffer("UTF-16");
|
||||
const PRUnichar* encoding = buffer.GetUnicode();
|
||||
if (encoding) {
|
||||
mExpatParser = XML_ParserCreate((const XML_Char*) encoding);
|
||||
gTokenRecycler=(CTokenRecycler*)GetTokenRecycler();
|
||||
if (mExpatParser) {
|
||||
SetupExpatCallbacks();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,10 +232,9 @@ void nsExpatTokenizer::PushXMLErrorToken(const char *aBuffer, PRUint32 aLength)
|
|||
AddToken(theToken, NS_OK, *gTokenDeque,gTokenRecycler);
|
||||
}
|
||||
|
||||
nsresult nsExpatTokenizer::ParseXMLBuffer(const char *aBuffer, PRUint32 aLength){
|
||||
nsresult nsExpatTokenizer::ParseXMLBuffer(const char* aBuffer, PRUint32 aLength){
|
||||
nsresult result=NS_OK;
|
||||
if (mExpatParser) {
|
||||
PR_ASSERT(aLength == strlen(aBuffer));
|
||||
if (!mSeenError) {
|
||||
if (!XML_Parse(mExpatParser, aBuffer, aLength, PR_FALSE)) {
|
||||
PushXMLErrorToken(aBuffer, aLength);
|
||||
|
@ -272,12 +272,12 @@ nsresult nsExpatTokenizer::ConsumeToken(nsScanner& aScanner) {
|
|||
nsString& theBuffer = aScanner.GetBuffer();
|
||||
PRInt32 length = theBuffer.Length();
|
||||
if(0 < length) {
|
||||
char* expatBuffer = theBuffer.ToNewCString();
|
||||
const PRUnichar* expatBuffer = theBuffer.GetUnicode();
|
||||
PRUint32 bufLength = theBuffer.Length() * 2;
|
||||
if (expatBuffer) {
|
||||
gTokenDeque=&mTokenDeque;
|
||||
gExpatParser = mExpatParser;
|
||||
result = ParseXMLBuffer(expatBuffer, length);
|
||||
delete [] expatBuffer;
|
||||
result = ParseXMLBuffer((const char *)expatBuffer, bufLength);
|
||||
}
|
||||
theBuffer.Truncate(0);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
#include "nsISupports.h"
|
||||
#include "nsHTMLTokenizer.h"
|
||||
#include "prtypes.h"
|
||||
|
||||
// Enable unicode characters in expat.
|
||||
#define XML_UNICODE_WCHAR_T
|
||||
#include "xmlparse.h"
|
||||
|
||||
#define NS_EXPATTOKENIZER_IID \
|
||||
|
|
|
@ -27,11 +27,8 @@
|
|||
#include "nsScanner.h"
|
||||
#include "nsDTDUtils.h"
|
||||
#include "nsParserError.h"
|
||||
// #include "nsParser.h"
|
||||
#include "nsIParser.h"
|
||||
#include "prlog.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/************************************************************************
|
||||
And now for the main class -- nsExpatTokenizer...
|
||||
|
@ -134,10 +131,14 @@ nsExpatTokenizer::nsExpatTokenizer() : nsHTMLTokenizer() {
|
|||
NS_INIT_REFCNT();
|
||||
mBytesParsed = 0;
|
||||
mSeenError = PR_FALSE;
|
||||
mExpatParser = XML_ParserCreate(NULL);
|
||||
gTokenRecycler=(CTokenRecycler*)GetTokenRecycler();
|
||||
if (mExpatParser) {
|
||||
SetupExpatCallbacks();
|
||||
nsAutoString buffer("UTF-16");
|
||||
const PRUnichar* encoding = buffer.GetUnicode();
|
||||
if (encoding) {
|
||||
mExpatParser = XML_ParserCreate((const XML_Char*) encoding);
|
||||
gTokenRecycler=(CTokenRecycler*)GetTokenRecycler();
|
||||
if (mExpatParser) {
|
||||
SetupExpatCallbacks();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -231,10 +232,9 @@ void nsExpatTokenizer::PushXMLErrorToken(const char *aBuffer, PRUint32 aLength)
|
|||
AddToken(theToken, NS_OK, *gTokenDeque,gTokenRecycler);
|
||||
}
|
||||
|
||||
nsresult nsExpatTokenizer::ParseXMLBuffer(const char *aBuffer, PRUint32 aLength){
|
||||
nsresult nsExpatTokenizer::ParseXMLBuffer(const char* aBuffer, PRUint32 aLength){
|
||||
nsresult result=NS_OK;
|
||||
if (mExpatParser) {
|
||||
PR_ASSERT(aLength == strlen(aBuffer));
|
||||
if (!mSeenError) {
|
||||
if (!XML_Parse(mExpatParser, aBuffer, aLength, PR_FALSE)) {
|
||||
PushXMLErrorToken(aBuffer, aLength);
|
||||
|
@ -272,12 +272,12 @@ nsresult nsExpatTokenizer::ConsumeToken(nsScanner& aScanner) {
|
|||
nsString& theBuffer = aScanner.GetBuffer();
|
||||
PRInt32 length = theBuffer.Length();
|
||||
if(0 < length) {
|
||||
char* expatBuffer = theBuffer.ToNewCString();
|
||||
const PRUnichar* expatBuffer = theBuffer.GetUnicode();
|
||||
PRUint32 bufLength = theBuffer.Length() * 2;
|
||||
if (expatBuffer) {
|
||||
gTokenDeque=&mTokenDeque;
|
||||
gExpatParser = mExpatParser;
|
||||
result = ParseXMLBuffer(expatBuffer, length);
|
||||
delete [] expatBuffer;
|
||||
result = ParseXMLBuffer((const char *)expatBuffer, bufLength);
|
||||
}
|
||||
theBuffer.Truncate(0);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
#include "nsISupports.h"
|
||||
#include "nsHTMLTokenizer.h"
|
||||
#include "prtypes.h"
|
||||
|
||||
// Enable unicode characters in expat.
|
||||
#define XML_UNICODE_WCHAR_T
|
||||
#include "xmlparse.h"
|
||||
|
||||
#define NS_EXPATTOKENIZER_IID \
|
||||
|
|
Загрузка…
Ссылка в новой задаче