зеркало из https://github.com/mozilla/pjs.git
added support for empty (XML) tags
This commit is contained in:
Родитель
0e63fbad18
Коммит
4a0993ec5f
|
@ -2393,17 +2393,30 @@ PRInt32 CNavDTD::ConsumeTag(PRUnichar aChar,CScanner& aScanner,CToken*& aToken)
|
|||
* @param aScanner: see nsScanner.h
|
||||
* @return
|
||||
*/
|
||||
PRInt32 CNavDTD::ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CToken*& aToken) {
|
||||
PRInt32 CNavDTD::ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CStartToken* aToken) {
|
||||
PRBool done=PR_FALSE;
|
||||
PRInt32 result=kNoError;
|
||||
nsAutoString as("");
|
||||
PRInt16 theAttrCount=0;
|
||||
|
||||
while((!done) && (result==kNoError)) {
|
||||
CToken* theToken= new CAttributeToken(as);
|
||||
CAttributeToken* theToken= new CAttributeToken(as);
|
||||
if(theToken){
|
||||
result=theToken->Consume(aChar,aScanner); //tell new token to finish consuming text...
|
||||
if(kNoError==result){
|
||||
|
||||
//Much as I hate to do this, here's some special case code.
|
||||
//This handles the case of empty-tags in XML. Our last
|
||||
//attribute token will come through with a text value of ""
|
||||
//and a textkey of "/". We should destroy it, and tell the
|
||||
//start token it was empty.
|
||||
nsString& key=theToken->GetKey();
|
||||
nsString& text=theToken->GetText();
|
||||
if((key[0]==kForwardSlash) && (0==text.Length())){
|
||||
//tada! our special case! Treat it like an empty start tag...
|
||||
aToken->SetEmpty(PR_TRUE);
|
||||
delete theToken;
|
||||
}
|
||||
else if(kNoError==result){
|
||||
theAttrCount++;
|
||||
mTokenDeque.Push(theToken);
|
||||
}//if
|
||||
|
@ -2459,12 +2472,12 @@ PRInt32 CNavDTD::ConsumeStartTag(PRUnichar aChar,CScanner& aScanner,CToken*& aTo
|
|||
PRInt32 result=kNoError;
|
||||
|
||||
aToken=new CStartToken(nsAutoString(""));
|
||||
|
||||
|
||||
if(aToken) {
|
||||
result= aToken->Consume(aChar,aScanner); //tell new token to finish consuming text...
|
||||
if(kNoError==result) {
|
||||
if(((CStartToken*)aToken)->IsAttributed()) {
|
||||
result=ConsumeAttributes(aChar,aScanner,aToken);
|
||||
result=ConsumeAttributes(aChar,aScanner,(CStartToken*)aToken);
|
||||
}
|
||||
//now that that's over with, we have one more problem to solve.
|
||||
//In the case that we just read a <SCRIPT> or <STYLE> tags, we should go and
|
||||
|
|
|
@ -613,7 +613,7 @@ private:
|
|||
* @param aToken is the next token (or null)
|
||||
* @return error code
|
||||
*/
|
||||
PRInt32 ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CToken*& aToken);
|
||||
PRInt32 ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CStartToken* aToken);
|
||||
|
||||
/**
|
||||
* Retrieve a sequence of text from given scanner.
|
||||
|
|
|
@ -2393,7 +2393,7 @@ PRInt32 COtherDTD::ConsumeTag(PRUnichar aChar,CScanner& aScanner,CToken*& aToken
|
|||
* @param aScanner: see nsScanner.h
|
||||
* @return
|
||||
*/
|
||||
PRInt32 COtherDTD::ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CToken*& aToken) {
|
||||
PRInt32 COtherDTD::ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CStartToken* aToken) {
|
||||
PRBool done=PR_FALSE;
|
||||
PRInt32 result=kNoError;
|
||||
nsAutoString as("");
|
||||
|
@ -2459,12 +2459,12 @@ PRInt32 COtherDTD::ConsumeStartTag(PRUnichar aChar,CScanner& aScanner,CToken*& a
|
|||
PRInt32 result=kNoError;
|
||||
|
||||
aToken=new CStartToken(nsAutoString(""));
|
||||
|
||||
|
||||
if(aToken) {
|
||||
result= aToken->Consume(aChar,aScanner); //tell new token to finish consuming text...
|
||||
if(kNoError==result) {
|
||||
if(((CStartToken*)aToken)->IsAttributed()) {
|
||||
result=ConsumeAttributes(aChar,aScanner,aToken);
|
||||
result=ConsumeAttributes(aChar,aScanner,(CStartToken*)aToken);
|
||||
}
|
||||
//now that that's over with, we have one more problem to solve.
|
||||
//In the case that we just read a <SCRIPT> or <STYLE> tags, we should go and
|
||||
|
|
|
@ -614,7 +614,7 @@ private:
|
|||
* @param aToken is the next token (or null)
|
||||
* @return error code
|
||||
*/
|
||||
PRInt32 ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CToken*& aToken);
|
||||
PRInt32 ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CStartToken* aToken);
|
||||
|
||||
/**
|
||||
* Retrieve a sequence of text from given scanner.
|
||||
|
|
|
@ -285,6 +285,7 @@ CHTMLToken::CHTMLToken(eHTMLTags aTag) : CToken(GetTagName(aTag)) {
|
|||
*/
|
||||
CStartToken::CStartToken(const nsString& aName) : CHTMLToken(aName) {
|
||||
mAttributed=PR_FALSE;
|
||||
mEmpty=PR_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -296,6 +297,7 @@ CStartToken::CStartToken(const nsString& aName) : CHTMLToken(aName) {
|
|||
*/
|
||||
CStartToken::CStartToken(eHTMLTags aTag) : CHTMLToken(aTag) {
|
||||
mAttributed=PR_FALSE;
|
||||
mEmpty=PR_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -355,6 +357,28 @@ PRBool CStartToken::IsAttributed(void) {
|
|||
return mAttributed;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void CStartToken::SetEmpty(PRBool aValue) {
|
||||
mEmpty=aValue;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRBool CStartToken::IsEmpty(void) {
|
||||
return mEmpty;
|
||||
}
|
||||
|
||||
/*
|
||||
* Consume the identifier portion of the start tag
|
||||
*
|
||||
|
|
|
@ -155,13 +155,15 @@ class CStartToken: public CHTMLToken {
|
|||
virtual PRInt32 GetTypeID(void);
|
||||
virtual const char* GetClassName(void);
|
||||
virtual PRInt32 GetTokenType(void);
|
||||
void SetAttributed(PRBool aValue);
|
||||
PRBool IsAttributed(void);
|
||||
void SetAttributed(PRBool aValue);
|
||||
PRBool IsEmpty(void);
|
||||
void SetEmpty(PRBool aValue);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
|
||||
protected:
|
||||
PRBool mAttributed;
|
||||
|
||||
PRBool mEmpty;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
//#define __INCREMENTAL 1
|
||||
|
||||
|
||||
#include "nsParser.h"
|
||||
#include "nsIContentSink.h"
|
||||
|
@ -31,13 +31,6 @@
|
|||
#include "nsIInputStream.h"
|
||||
#include "nsIParserFilter.h"
|
||||
|
||||
/* UNCOMMENT THIS IF STUFF STOPS WORKING...
|
||||
#ifdef XP_PC
|
||||
#include <direct.h> //this is here for debug reasons...
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include "prmem.h"
|
||||
*/
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kClassIID, NS_PARSER_IID);
|
||||
|
|
|
@ -322,7 +322,7 @@ PRInt32 CScanner::GetChar(PRUnichar& aChar) {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 CScanner::Peek(PRUnichar& aChar){
|
||||
PRInt32 CScanner::Peek(PRUnichar& aChar) {
|
||||
PRInt32 result=Eof();
|
||||
if(!result) {
|
||||
aChar=mBuffer[mOffset];
|
||||
|
|
|
@ -2393,17 +2393,30 @@ PRInt32 CNavDTD::ConsumeTag(PRUnichar aChar,CScanner& aScanner,CToken*& aToken)
|
|||
* @param aScanner: see nsScanner.h
|
||||
* @return
|
||||
*/
|
||||
PRInt32 CNavDTD::ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CToken*& aToken) {
|
||||
PRInt32 CNavDTD::ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CStartToken* aToken) {
|
||||
PRBool done=PR_FALSE;
|
||||
PRInt32 result=kNoError;
|
||||
nsAutoString as("");
|
||||
PRInt16 theAttrCount=0;
|
||||
|
||||
while((!done) && (result==kNoError)) {
|
||||
CToken* theToken= new CAttributeToken(as);
|
||||
CAttributeToken* theToken= new CAttributeToken(as);
|
||||
if(theToken){
|
||||
result=theToken->Consume(aChar,aScanner); //tell new token to finish consuming text...
|
||||
if(kNoError==result){
|
||||
|
||||
//Much as I hate to do this, here's some special case code.
|
||||
//This handles the case of empty-tags in XML. Our last
|
||||
//attribute token will come through with a text value of ""
|
||||
//and a textkey of "/". We should destroy it, and tell the
|
||||
//start token it was empty.
|
||||
nsString& key=theToken->GetKey();
|
||||
nsString& text=theToken->GetText();
|
||||
if((key[0]==kForwardSlash) && (0==text.Length())){
|
||||
//tada! our special case! Treat it like an empty start tag...
|
||||
aToken->SetEmpty(PR_TRUE);
|
||||
delete theToken;
|
||||
}
|
||||
else if(kNoError==result){
|
||||
theAttrCount++;
|
||||
mTokenDeque.Push(theToken);
|
||||
}//if
|
||||
|
@ -2459,12 +2472,12 @@ PRInt32 CNavDTD::ConsumeStartTag(PRUnichar aChar,CScanner& aScanner,CToken*& aTo
|
|||
PRInt32 result=kNoError;
|
||||
|
||||
aToken=new CStartToken(nsAutoString(""));
|
||||
|
||||
|
||||
if(aToken) {
|
||||
result= aToken->Consume(aChar,aScanner); //tell new token to finish consuming text...
|
||||
if(kNoError==result) {
|
||||
if(((CStartToken*)aToken)->IsAttributed()) {
|
||||
result=ConsumeAttributes(aChar,aScanner,aToken);
|
||||
result=ConsumeAttributes(aChar,aScanner,(CStartToken*)aToken);
|
||||
}
|
||||
//now that that's over with, we have one more problem to solve.
|
||||
//In the case that we just read a <SCRIPT> or <STYLE> tags, we should go and
|
||||
|
|
|
@ -613,7 +613,7 @@ private:
|
|||
* @param aToken is the next token (or null)
|
||||
* @return error code
|
||||
*/
|
||||
PRInt32 ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CToken*& aToken);
|
||||
PRInt32 ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CStartToken* aToken);
|
||||
|
||||
/**
|
||||
* Retrieve a sequence of text from given scanner.
|
||||
|
|
|
@ -2393,7 +2393,7 @@ PRInt32 COtherDTD::ConsumeTag(PRUnichar aChar,CScanner& aScanner,CToken*& aToken
|
|||
* @param aScanner: see nsScanner.h
|
||||
* @return
|
||||
*/
|
||||
PRInt32 COtherDTD::ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CToken*& aToken) {
|
||||
PRInt32 COtherDTD::ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CStartToken* aToken) {
|
||||
PRBool done=PR_FALSE;
|
||||
PRInt32 result=kNoError;
|
||||
nsAutoString as("");
|
||||
|
@ -2459,12 +2459,12 @@ PRInt32 COtherDTD::ConsumeStartTag(PRUnichar aChar,CScanner& aScanner,CToken*& a
|
|||
PRInt32 result=kNoError;
|
||||
|
||||
aToken=new CStartToken(nsAutoString(""));
|
||||
|
||||
|
||||
if(aToken) {
|
||||
result= aToken->Consume(aChar,aScanner); //tell new token to finish consuming text...
|
||||
if(kNoError==result) {
|
||||
if(((CStartToken*)aToken)->IsAttributed()) {
|
||||
result=ConsumeAttributes(aChar,aScanner,aToken);
|
||||
result=ConsumeAttributes(aChar,aScanner,(CStartToken*)aToken);
|
||||
}
|
||||
//now that that's over with, we have one more problem to solve.
|
||||
//In the case that we just read a <SCRIPT> or <STYLE> tags, we should go and
|
||||
|
|
|
@ -614,7 +614,7 @@ private:
|
|||
* @param aToken is the next token (or null)
|
||||
* @return error code
|
||||
*/
|
||||
PRInt32 ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CToken*& aToken);
|
||||
PRInt32 ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CStartToken* aToken);
|
||||
|
||||
/**
|
||||
* Retrieve a sequence of text from given scanner.
|
||||
|
|
|
@ -285,6 +285,7 @@ CHTMLToken::CHTMLToken(eHTMLTags aTag) : CToken(GetTagName(aTag)) {
|
|||
*/
|
||||
CStartToken::CStartToken(const nsString& aName) : CHTMLToken(aName) {
|
||||
mAttributed=PR_FALSE;
|
||||
mEmpty=PR_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -296,6 +297,7 @@ CStartToken::CStartToken(const nsString& aName) : CHTMLToken(aName) {
|
|||
*/
|
||||
CStartToken::CStartToken(eHTMLTags aTag) : CHTMLToken(aTag) {
|
||||
mAttributed=PR_FALSE;
|
||||
mEmpty=PR_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -355,6 +357,28 @@ PRBool CStartToken::IsAttributed(void) {
|
|||
return mAttributed;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void CStartToken::SetEmpty(PRBool aValue) {
|
||||
mEmpty=aValue;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRBool CStartToken::IsEmpty(void) {
|
||||
return mEmpty;
|
||||
}
|
||||
|
||||
/*
|
||||
* Consume the identifier portion of the start tag
|
||||
*
|
||||
|
|
|
@ -155,13 +155,15 @@ class CStartToken: public CHTMLToken {
|
|||
virtual PRInt32 GetTypeID(void);
|
||||
virtual const char* GetClassName(void);
|
||||
virtual PRInt32 GetTokenType(void);
|
||||
void SetAttributed(PRBool aValue);
|
||||
PRBool IsAttributed(void);
|
||||
void SetAttributed(PRBool aValue);
|
||||
PRBool IsEmpty(void);
|
||||
void SetEmpty(PRBool aValue);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
|
||||
protected:
|
||||
PRBool mAttributed;
|
||||
|
||||
PRBool mEmpty;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* Reserved.
|
||||
*/
|
||||
|
||||
//#define __INCREMENTAL 1
|
||||
|
||||
|
||||
#include "nsParser.h"
|
||||
#include "nsIContentSink.h"
|
||||
|
@ -31,13 +31,6 @@
|
|||
#include "nsIInputStream.h"
|
||||
#include "nsIParserFilter.h"
|
||||
|
||||
/* UNCOMMENT THIS IF STUFF STOPS WORKING...
|
||||
#ifdef XP_PC
|
||||
#include <direct.h> //this is here for debug reasons...
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include "prmem.h"
|
||||
*/
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kClassIID, NS_PARSER_IID);
|
||||
|
|
|
@ -322,7 +322,7 @@ PRInt32 CScanner::GetChar(PRUnichar& aChar) {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 CScanner::Peek(PRUnichar& aChar){
|
||||
PRInt32 CScanner::Peek(PRUnichar& aChar) {
|
||||
PRInt32 result=Eof();
|
||||
if(!result) {
|
||||
aChar=mBuffer[mOffset];
|
||||
|
|
Загрузка…
Ссылка в новой задаче