fixed general closure case

This commit is contained in:
rickg 1998-05-04 23:36:46 +00:00
parent 7fbcd5a7da
commit 6b8c5225ba
14 changed files with 248 additions and 18 deletions

View File

@ -129,6 +129,12 @@ static char formElementTags[]= {
eHTMLTag_isindex, eHTMLTag_label, eHTMLTag_legend,
eHTMLTag_select, eHTMLTag_textarea,0};
static char gHeadingTags[]={
eHTMLTag_h1, eHTMLTag_h2, eHTMLTag_h3,
eHTMLTag_h4, eHTMLTag_h5, eHTMLTag_h6,
0};
/**
* This method is called to determine whether or not a tag
* of one type can contain a tag of another type.
@ -143,6 +149,7 @@ PRBool CNavDTD::CanContainFormElement(PRInt32 aParent,PRInt32 aChild) const {
return result;
}
/**
* This method is called to determine whether or not a tag
* of one type can contain a tag of another type.
@ -341,10 +348,7 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
case eHTMLTag_h3: case eHTMLTag_h4:
case eHTMLTag_h5: case eHTMLTag_h6:
{
static char badTags[]={
eHTMLTag_h1, eHTMLTag_h2, eHTMLTag_h3,
eHTMLTag_h4, eHTMLTag_h5, eHTMLTag_h6, 0};
if(0!=strchr(badTags,aChild))
if(0!=strchr(gHeadingTags,aChild))
result=PR_FALSE;
else result=PRBool(0!=strchr(gTagSet1,aChild));
}
@ -635,6 +639,68 @@ PRBool CNavDTD::CanOmit(PRInt32 aParent,PRInt32 aChild) const {
return result;
}
/**
* This method gets called to determine whether a given
* ENDtag can be omitted. Admittedly,this is a gross simplification.
*
* @update gess 3/25/98
* @param aTag -- tag to test for containership
* @return PR_TRUE if given tag can contain other tags
*/
PRBool CNavDTD::CanOmitEndTag(PRInt32 aParent,PRInt32 aChild) const {
PRBool result=PR_FALSE;
//begin with some simple (and obvious) cases...
switch((eHTMLTags)aChild) {
case eHTMLTag_userdefined:
case eHTMLTag_comment:
result=PR_TRUE;
break;
case eHTMLTag_h1: case eHTMLTag_h2:
case eHTMLTag_h3: case eHTMLTag_h4:
case eHTMLTag_h5: case eHTMLTag_h6:
{
if(0!=strchr(gHeadingTags,aParent))
result=PR_FALSE;
//Actually, we probably need to walk the stack here...
else result=PR_TRUE;
}
break;
case eHTMLTag_button: case eHTMLTag_fieldset:
case eHTMLTag_input: case eHTMLTag_isindex:
case eHTMLTag_label: case eHTMLTag_legend:
case eHTMLTag_select: case eHTMLTag_textarea:
if(PR_FALSE==mParser->HasOpenForm())
result=PR_TRUE;
break;
case eHTMLTag_newline:
case eHTMLTag_whitespace:
switch((eHTMLTags)aParent) {
case eHTMLTag_html: case eHTMLTag_head:
case eHTMLTag_title: case eHTMLTag_map:
case eHTMLTag_tr: case eHTMLTag_table:
case eHTMLTag_thead: case eHTMLTag_tfoot:
case eHTMLTag_tbody: case eHTMLTag_col:
case eHTMLTag_colgroup: case eHTMLTag_unknown:
result=PR_TRUE;
default:
break;
} //switch
break;
default:
if(aChild!=aParent)
result=PR_TRUE;
break;
} //switch
return result;
}
/**
* This method gets called to determine whether a given
* tag is itself a container

View File

@ -104,6 +104,17 @@ class CNavDTD : public nsIDTD {
*/
virtual PRBool CanOmit(PRInt32 aParent,PRInt32 aChild)const;
/**
* This method gets called to determine whether a given
* tag can contain newlines. Most do not.
*
* @update gess 3/25/98
* @param aParent -- tag type of parent
* @param aChild -- tag type of child
* @return PR_TRUE if given tag can contain other tags
*/
virtual PRBool CanOmitEndTag(PRInt32 aParent,PRInt32 aChild)const;
/**
* This method gets called to determine whether a given
* tag is itself a container

View File

@ -556,6 +556,19 @@ PRBool COtherDTD::CanOmit(PRInt32 aParent,PRInt32 aChild) const {
return result;
}
/**
* This method gets called to determine whether a given
* tag can contain newlines. Most do not.
*
* @update gess 3/25/98
* @param aTag -- tag to test for containership
* @return PR_TRUE if given tag can contain other tags
*/
PRBool COtherDTD::CanOmitEndTag(PRInt32 aParent,PRInt32 aChild) const {
PRBool result=PR_FALSE;
return result;
}
/**
* This method gets called to determine whether a given
* tag is itself a container

View File

@ -106,6 +106,17 @@ class COtherDTD : public nsIDTD {
*/
virtual PRBool CanOmit(PRInt32 aParent,PRInt32 aChild)const;
/**
* This method gets called to determine whether a given
* tag can contain newlines. Most do not.
*
* @update gess 3/25/98
* @param aParent -- tag type of parent
* @param aChild -- tag type of child
* @return PR_TRUE if given tag can contain other tags
*/
virtual PRBool CanOmitEndTag(PRInt32 aParent,PRInt32 aChild)const;
/**
* This method gets called to determine whether a given
* tag is itself a container

View File

@ -760,11 +760,11 @@ PRBool nsHTMLParser::HandleEndToken(CToken* aToken) {
NS_PRECONDITION(0!=aToken,kNullToken);
PRBool result=PR_FALSE;
CEndToken* st = (CEndToken*)(aToken);
eHTMLTags tokenTagType=st->GetHTMLTag();
CEndToken* et = (CEndToken*)(aToken);
eHTMLTags tokenTagType=et->GetHTMLTag();
//now check to see if this token should be omitted...
if(PR_TRUE==mDTD->CanOmit(GetTopNode(),tokenTagType)) {
if(PR_TRUE==mDTD->CanOmitEndTag(GetTopNode(),tokenTagType)) {
return PR_TRUE;
}

View File

@ -95,6 +95,17 @@ class nsIDTD : public nsISupports {
*/
virtual PRBool CanOmit(PRInt32 aParent,PRInt32 aChild)const=0;
/**
* This method gets called to determine whether a given
* tag can contain newlines. Most do not.
*
* @update gess 3/25/98
* @param aParent -- tag type of parent
* @param aChild -- tag type of child
* @return PR_TRUE if given tag can contain other tags
*/
virtual PRBool CanOmitEndTag(PRInt32 aParent,PRInt32 aChild)const=0;
/**
* This method gets called at various times by the parser
* whenever we want to verify a valid context stack. This

View File

@ -53,8 +53,11 @@ CScanner::CScanner(nsIURL* aURL,eParseMode aMode) : mBuffer("") {
* @return
*/
CScanner::~CScanner() {
mStream->Close();
mStream->Release();
if(mStream) {
mStream->Close();
mStream->Release();
mStream=0;
}
}

View File

@ -129,6 +129,12 @@ static char formElementTags[]= {
eHTMLTag_isindex, eHTMLTag_label, eHTMLTag_legend,
eHTMLTag_select, eHTMLTag_textarea,0};
static char gHeadingTags[]={
eHTMLTag_h1, eHTMLTag_h2, eHTMLTag_h3,
eHTMLTag_h4, eHTMLTag_h5, eHTMLTag_h6,
0};
/**
* This method is called to determine whether or not a tag
* of one type can contain a tag of another type.
@ -143,6 +149,7 @@ PRBool CNavDTD::CanContainFormElement(PRInt32 aParent,PRInt32 aChild) const {
return result;
}
/**
* This method is called to determine whether or not a tag
* of one type can contain a tag of another type.
@ -341,10 +348,7 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
case eHTMLTag_h3: case eHTMLTag_h4:
case eHTMLTag_h5: case eHTMLTag_h6:
{
static char badTags[]={
eHTMLTag_h1, eHTMLTag_h2, eHTMLTag_h3,
eHTMLTag_h4, eHTMLTag_h5, eHTMLTag_h6, 0};
if(0!=strchr(badTags,aChild))
if(0!=strchr(gHeadingTags,aChild))
result=PR_FALSE;
else result=PRBool(0!=strchr(gTagSet1,aChild));
}
@ -635,6 +639,68 @@ PRBool CNavDTD::CanOmit(PRInt32 aParent,PRInt32 aChild) const {
return result;
}
/**
* This method gets called to determine whether a given
* ENDtag can be omitted. Admittedly,this is a gross simplification.
*
* @update gess 3/25/98
* @param aTag -- tag to test for containership
* @return PR_TRUE if given tag can contain other tags
*/
PRBool CNavDTD::CanOmitEndTag(PRInt32 aParent,PRInt32 aChild) const {
PRBool result=PR_FALSE;
//begin with some simple (and obvious) cases...
switch((eHTMLTags)aChild) {
case eHTMLTag_userdefined:
case eHTMLTag_comment:
result=PR_TRUE;
break;
case eHTMLTag_h1: case eHTMLTag_h2:
case eHTMLTag_h3: case eHTMLTag_h4:
case eHTMLTag_h5: case eHTMLTag_h6:
{
if(0!=strchr(gHeadingTags,aParent))
result=PR_FALSE;
//Actually, we probably need to walk the stack here...
else result=PR_TRUE;
}
break;
case eHTMLTag_button: case eHTMLTag_fieldset:
case eHTMLTag_input: case eHTMLTag_isindex:
case eHTMLTag_label: case eHTMLTag_legend:
case eHTMLTag_select: case eHTMLTag_textarea:
if(PR_FALSE==mParser->HasOpenForm())
result=PR_TRUE;
break;
case eHTMLTag_newline:
case eHTMLTag_whitespace:
switch((eHTMLTags)aParent) {
case eHTMLTag_html: case eHTMLTag_head:
case eHTMLTag_title: case eHTMLTag_map:
case eHTMLTag_tr: case eHTMLTag_table:
case eHTMLTag_thead: case eHTMLTag_tfoot:
case eHTMLTag_tbody: case eHTMLTag_col:
case eHTMLTag_colgroup: case eHTMLTag_unknown:
result=PR_TRUE;
default:
break;
} //switch
break;
default:
if(aChild!=aParent)
result=PR_TRUE;
break;
} //switch
return result;
}
/**
* This method gets called to determine whether a given
* tag is itself a container

View File

@ -104,6 +104,17 @@ class CNavDTD : public nsIDTD {
*/
virtual PRBool CanOmit(PRInt32 aParent,PRInt32 aChild)const;
/**
* This method gets called to determine whether a given
* tag can contain newlines. Most do not.
*
* @update gess 3/25/98
* @param aParent -- tag type of parent
* @param aChild -- tag type of child
* @return PR_TRUE if given tag can contain other tags
*/
virtual PRBool CanOmitEndTag(PRInt32 aParent,PRInt32 aChild)const;
/**
* This method gets called to determine whether a given
* tag is itself a container

View File

@ -556,6 +556,19 @@ PRBool COtherDTD::CanOmit(PRInt32 aParent,PRInt32 aChild) const {
return result;
}
/**
* This method gets called to determine whether a given
* tag can contain newlines. Most do not.
*
* @update gess 3/25/98
* @param aTag -- tag to test for containership
* @return PR_TRUE if given tag can contain other tags
*/
PRBool COtherDTD::CanOmitEndTag(PRInt32 aParent,PRInt32 aChild) const {
PRBool result=PR_FALSE;
return result;
}
/**
* This method gets called to determine whether a given
* tag is itself a container

View File

@ -106,6 +106,17 @@ class COtherDTD : public nsIDTD {
*/
virtual PRBool CanOmit(PRInt32 aParent,PRInt32 aChild)const;
/**
* This method gets called to determine whether a given
* tag can contain newlines. Most do not.
*
* @update gess 3/25/98
* @param aParent -- tag type of parent
* @param aChild -- tag type of child
* @return PR_TRUE if given tag can contain other tags
*/
virtual PRBool CanOmitEndTag(PRInt32 aParent,PRInt32 aChild)const;
/**
* This method gets called to determine whether a given
* tag is itself a container

View File

@ -760,11 +760,11 @@ PRBool nsHTMLParser::HandleEndToken(CToken* aToken) {
NS_PRECONDITION(0!=aToken,kNullToken);
PRBool result=PR_FALSE;
CEndToken* st = (CEndToken*)(aToken);
eHTMLTags tokenTagType=st->GetHTMLTag();
CEndToken* et = (CEndToken*)(aToken);
eHTMLTags tokenTagType=et->GetHTMLTag();
//now check to see if this token should be omitted...
if(PR_TRUE==mDTD->CanOmit(GetTopNode(),tokenTagType)) {
if(PR_TRUE==mDTD->CanOmitEndTag(GetTopNode(),tokenTagType)) {
return PR_TRUE;
}

View File

@ -95,6 +95,17 @@ class nsIDTD : public nsISupports {
*/
virtual PRBool CanOmit(PRInt32 aParent,PRInt32 aChild)const=0;
/**
* This method gets called to determine whether a given
* tag can contain newlines. Most do not.
*
* @update gess 3/25/98
* @param aParent -- tag type of parent
* @param aChild -- tag type of child
* @return PR_TRUE if given tag can contain other tags
*/
virtual PRBool CanOmitEndTag(PRInt32 aParent,PRInt32 aChild)const=0;
/**
* This method gets called at various times by the parser
* whenever we want to verify a valid context stack. This

View File

@ -53,8 +53,11 @@ CScanner::CScanner(nsIURL* aURL,eParseMode aMode) : mBuffer("") {
* @return
*/
CScanner::~CScanner() {
mStream->Close();
mStream->Release();
if(mStream) {
mStream->Close();
mStream->Release();
mStream=0;
}
}