From 1a752708f941ddf542dddebe7c7c14c3c0ff5c2f Mon Sep 17 00:00:00 2001 From: rickg Date: Sat, 20 Jun 1998 00:12:10 +0000 Subject: [PATCH] added support for empty (XML) tags git-svn-id: svn://10.0.0.236/trunk@4178 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/htmlparser/src/CNavDTD.cpp | 23 ++++++++++++++---- mozilla/htmlparser/src/CNavDTD.h | 2 +- mozilla/htmlparser/src/COtherDTD.cpp | 6 ++--- mozilla/htmlparser/src/COtherDTD.h | 2 +- mozilla/htmlparser/src/nsHTMLTokens.cpp | 24 +++++++++++++++++++ mozilla/htmlparser/src/nsHTMLTokens.h | 6 +++-- mozilla/htmlparser/src/nsParser.cpp | 9 +------ mozilla/htmlparser/src/nsScanner.cpp | 2 +- mozilla/parser/htmlparser/src/CNavDTD.cpp | 23 ++++++++++++++---- mozilla/parser/htmlparser/src/CNavDTD.h | 2 +- mozilla/parser/htmlparser/src/COtherDTD.cpp | 6 ++--- mozilla/parser/htmlparser/src/COtherDTD.h | 2 +- .../parser/htmlparser/src/nsHTMLTokens.cpp | 24 +++++++++++++++++++ mozilla/parser/htmlparser/src/nsHTMLTokens.h | 6 +++-- mozilla/parser/htmlparser/src/nsParser.cpp | 9 +------ mozilla/parser/htmlparser/src/nsScanner.cpp | 2 +- 16 files changed, 106 insertions(+), 42 deletions(-) diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp index 8d17415a202..08650f5ddef 100644 --- a/mozilla/htmlparser/src/CNavDTD.cpp +++ b/mozilla/htmlparser/src/CNavDTD.cpp @@ -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