minor improvement to backward propagation code

This commit is contained in:
rickg 1998-04-30 22:06:16 +00:00
parent e302ceefde
commit 2d00aace40
4 changed files with 62 additions and 44 deletions

View File

@ -628,7 +628,8 @@ PRBool CNavDTD::CanOmit(PRInt32 aParent,PRInt32 aChild) const {
default:
if(eHTMLTag_unknown==aParent)
result=PRBool(eHTMLTag_html!=aChild);
result=PR_FALSE;
// result=PRBool(eHTMLTag_html!=aChild);
break;
} //switch
return result;
@ -686,7 +687,7 @@ PRInt32 CNavDTD::GetDefaultParentTagFor(PRInt32 aTag) const{
result=eHTMLTag_paragraph; break;
case eHTMLTag_html:
result=(eHTMLTags)kNotFound; break;
result=eHTMLTag_unknown; break;
case eHTMLTag_body:
case eHTMLTag_head:
@ -832,10 +833,10 @@ PRBool CNavDTD::BackwardPropagate(nsString& aVector,PRInt32 aParentTag,PRInt32 a
// aVector.Append((PRUnichar)aChildTag);
do {
theParentTag=(eHTMLTags)GetDefaultParentTagFor(theParentTag);
if(theParentTag!=kNotFound) {
if(theParentTag!=eHTMLTag_unknown) {
aVector.Append((PRUnichar)theParentTag);
}
} while((theParentTag!=kNotFound) && (theParentTag!=aParentTag));
} while((theParentTag!=eHTMLTag_unknown) && (theParentTag!=aParentTag));
return PRBool(aParentTag==theParentTag);
}

View File

@ -1315,25 +1315,33 @@ PRBool nsHTMLParser::CreateContextStackFor(PRInt32 aChildTag){
cnt=theVector.Length()-1;
result=PRBool(mContextStack[mContextStackPos-1]==theVector[cnt]);
}
else if(PR_TRUE==mDTD->BackwardPropagate(theVector,theTop,aChildTag)) {
if(theTop!=eHTMLTag_html)
mDTD->BackwardPropagate(theVector,eHTMLTag_html,theTop);
else {
PRBool tempResult;
if(eHTMLTag_unknown!=theTop) {
tempResult=mDTD->BackwardPropagate(theVector,theTop,aChildTag);
if(eHTMLTag_html!=theTop)
mDTD->BackwardPropagate(theVector,eHTMLTag_html,theTop);
}
else tempResult=mDTD->BackwardPropagate(theVector,eHTMLTag_html,aChildTag);
//propagation worked, so pop unwanted containers, push new ones, then exit...
pos=0;
cnt=theVector.Length();
result=PR_TRUE;
while(pos<mContextStackPos) {
if(mContextStack[pos]==theVector[cnt-1-pos]) {
pos++;
}
else {
//if you're here, you have something on the stack
//that doesn't match your needed tags order.
result=CloseContainersTo(pos);
break;
}
} //while
if(PR_TRUE==tempResult) {
//propagation worked, so pop unwanted containers, push new ones, then exit...
pos=0;
cnt=theVector.Length();
result=PR_TRUE;
while(pos<mContextStackPos) {
if(mContextStack[pos]==theVector[cnt-1-pos]) {
pos++;
}
else {
//if you're here, you have something on the stack
//that doesn't match your needed tags order.
result=CloseContainersTo(pos);
break;
}
} //while
} //elseif
} //elseif
//now, build up the stack according to the tags

View File

@ -628,7 +628,8 @@ PRBool CNavDTD::CanOmit(PRInt32 aParent,PRInt32 aChild) const {
default:
if(eHTMLTag_unknown==aParent)
result=PRBool(eHTMLTag_html!=aChild);
result=PR_FALSE;
// result=PRBool(eHTMLTag_html!=aChild);
break;
} //switch
return result;
@ -686,7 +687,7 @@ PRInt32 CNavDTD::GetDefaultParentTagFor(PRInt32 aTag) const{
result=eHTMLTag_paragraph; break;
case eHTMLTag_html:
result=(eHTMLTags)kNotFound; break;
result=eHTMLTag_unknown; break;
case eHTMLTag_body:
case eHTMLTag_head:
@ -832,10 +833,10 @@ PRBool CNavDTD::BackwardPropagate(nsString& aVector,PRInt32 aParentTag,PRInt32 a
// aVector.Append((PRUnichar)aChildTag);
do {
theParentTag=(eHTMLTags)GetDefaultParentTagFor(theParentTag);
if(theParentTag!=kNotFound) {
if(theParentTag!=eHTMLTag_unknown) {
aVector.Append((PRUnichar)theParentTag);
}
} while((theParentTag!=kNotFound) && (theParentTag!=aParentTag));
} while((theParentTag!=eHTMLTag_unknown) && (theParentTag!=aParentTag));
return PRBool(aParentTag==theParentTag);
}

View File

@ -1315,25 +1315,33 @@ PRBool nsHTMLParser::CreateContextStackFor(PRInt32 aChildTag){
cnt=theVector.Length()-1;
result=PRBool(mContextStack[mContextStackPos-1]==theVector[cnt]);
}
else if(PR_TRUE==mDTD->BackwardPropagate(theVector,theTop,aChildTag)) {
if(theTop!=eHTMLTag_html)
mDTD->BackwardPropagate(theVector,eHTMLTag_html,theTop);
else {
PRBool tempResult;
if(eHTMLTag_unknown!=theTop) {
tempResult=mDTD->BackwardPropagate(theVector,theTop,aChildTag);
if(eHTMLTag_html!=theTop)
mDTD->BackwardPropagate(theVector,eHTMLTag_html,theTop);
}
else tempResult=mDTD->BackwardPropagate(theVector,eHTMLTag_html,aChildTag);
//propagation worked, so pop unwanted containers, push new ones, then exit...
pos=0;
cnt=theVector.Length();
result=PR_TRUE;
while(pos<mContextStackPos) {
if(mContextStack[pos]==theVector[cnt-1-pos]) {
pos++;
}
else {
//if you're here, you have something on the stack
//that doesn't match your needed tags order.
result=CloseContainersTo(pos);
break;
}
} //while
if(PR_TRUE==tempResult) {
//propagation worked, so pop unwanted containers, push new ones, then exit...
pos=0;
cnt=theVector.Length();
result=PR_TRUE;
while(pos<mContextStackPos) {
if(mContextStack[pos]==theVector[cnt-1-pos]) {
pos++;
}
else {
//if you're here, you have something on the stack
//that doesn't match your needed tags order.
result=CloseContainersTo(pos);
break;
}
} //while
} //elseif
} //elseif
//now, build up the stack according to the tags