Added methods to support illegal-contents

This commit is contained in:
harishd%netscape.com 1999-04-15 20:12:41 +00:00
Родитель 6ddea62873
Коммит cfb7df54de
2 изменённых файлов: 214 добавлений и 130 удалений

Просмотреть файл

@ -28,125 +28,164 @@
/** /**
* Default constructor * Default constructor
* @update gess9/10/98 * @update harishd 04/04/99
*/ */
nsTagStack::nsTagStack(int aDefaultSize) { nsTagStack::nsTagStack(int aDefaultSize) {
mCapacity=aDefaultSize; mTags =new nsDeque(nsnull);
mCount=0;
#ifndef NS_DEBUG
mTags =new eHTMLTags[mCapacity];
#endif
nsCRT::zero(mTags,mCapacity*sizeof(eHTMLTags));
} }
/** /**
* Default destructor * Default destructor
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
nsTagStack::~nsTagStack() { nsTagStack::~nsTagStack() {
#ifndef NS_DEBUG
delete mTags; delete mTags;
mTags=0;
#endif
mCapacity=mCount=0;
} }
/** /**
* Resets state of stack to be empty. * Resets state of stack to be empty.
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
void nsTagStack::Empty(void) { void nsTagStack::Empty(void) {
mCount=0; mTags->Empty();
} }
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
void nsTagStack::Push(eHTMLTags aTag) { void nsTagStack::Push(eHTMLTags aTag) {
if(mCount>=mCapacity) { nsTags* result = new nsTags();
#ifndef NS_DEBUG result->mTag=aTag;
eHTMLTags* tmp=new eHTMLTags[2*mCapacity]; mTags->Push(result);
nsCRT::zero(tmp,2*mCapacity*sizeof(eHTMLTag_html));
nsCRT::memcpy(tmp,mTags,mCapacity*sizeof(eHTMLTag_html));
delete mTags;
mTags=tmp;
#else
NS_PRECONDITION(mCount<eStackSize,"TagStack Overflow: DEBUG VERSION!");
#endif
}
mTags[mCount++]=aTag;
} }
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
eHTMLTags nsTagStack::Pop() { eHTMLTags nsTagStack::Pop() {
eHTMLTags result=eHTMLTag_unknown; eHTMLTags result=eHTMLTag_unknown;
if(mCount>0) { if(mTags->GetSize() > 0) {
result=mTags[--mCount]; nsTags* t = (nsTags*)mTags->Pop();
mTags[mCount]=eHTMLTag_unknown; result=t->mTag;
delete t;
} }
return result; return result;
} }
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
eHTMLTags nsTagStack::First() const { eHTMLTags nsTagStack::First() const {
if(mCount>0) if(mTags->GetSize() > 0) {
return mTags[0]; nsTags* result = (nsTags*)mTags->Peek();
return result->mTag;
}
return eHTMLTag_unknown; return eHTMLTag_unknown;
} }
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
eHTMLTags nsTagStack::TagAt(PRInt32 anIndex) const { eHTMLTags nsTagStack::TagAt(PRInt32 anIndex) const {
if((anIndex>=0) && (anIndex<mCount)) if((anIndex>=0) && (anIndex<mTags->GetSize())) {
return mTags[anIndex]; nsTags* result = (nsTags*)mTags->ObjectAt(anIndex);
return result->mTag;
}
return eHTMLTag_unknown; return eHTMLTag_unknown;
}
}
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
eHTMLTags nsTagStack::operator[](PRInt32 anIndex) const { eHTMLTags nsTagStack::operator[](PRInt32 anIndex) const {
if((anIndex>=0) && (anIndex<mCount)) if((anIndex>=0) && (anIndex<mTags->GetSize())) {
return mTags[anIndex]; nsTags* result = (nsTags*)mTags->ObjectAt(anIndex);
return result->mTag;
}
return eHTMLTag_unknown; return eHTMLTag_unknown;
} }
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
eHTMLTags nsTagStack::Last() const { eHTMLTags nsTagStack::Last() const {
if(mCount>0) PRInt32 size = mTags->GetSize();
return mTags[mCount-1]; if(size > 0) {
nsTags* result = (nsTags*)mTags->ObjectAt(size - 1);
return result->mTag;
}
return eHTMLTag_unknown; return eHTMLTag_unknown;
} }
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
PRInt32 nsTagStack::GetTopmostIndexOf(eHTMLTags aTag) const { PRInt32 nsTagStack::GetTopmostIndexOf(eHTMLTags aTag) const {
int theIndex=0; int theIndex=0;
for(theIndex=mCount-1;theIndex>=0;theIndex--){ nsTags* result;
if(mTags[theIndex]==aTag) for(theIndex=(mTags->GetSize() - 1);theIndex>=0;theIndex--){
result = (nsTags*)mTags->ObjectAt(theIndex);
if(result->mTag==aTag)
return theIndex; return theIndex;
} }
return kNotFound; return kNotFound;
} }
/**
*
* @update harishd 04/04/99
*/
void nsTagStack::SaveToken(CToken* aToken, PRInt32 aID)
{
NS_PRECONDITION(aID <= mTags->GetSize() && aID > -1,"Out of bounds");
if(aToken) {
nsTags* result = (nsTags*)mTags->ObjectAt(aID);
result->mTokenBank->Push(aToken);
}
}
/**
*
* @update harishd 04/04/99
*/
CToken* nsTagStack::RestoreTokenFrom(PRInt32 aID)
{
NS_PRECONDITION(aID <= mTags->GetSize() && aID > -1,"Out of bounds");
if(mTags->GetSize() > 0) {
nsTags* result = (nsTags*)mTags->ObjectAt(aID);
return (CToken*)result->mTokenBank->PopFront();
}
return nsnull;
}
/**
*
* @update harishd 04/04/99
*/
PRInt32 nsTagStack::TokenCountAt(PRInt32 aID)
{
NS_PRECONDITION(aID <= mTags->GetSize(),"Out of bounds");
if(aID < 0)
return kNotFound;
nsTags* result = (nsTags*)mTags->ObjectAt(aID);
return result->mTokenBank->GetSize();
}
/*************************************************************** /***************************************************************
Now define the dtdcontext class Now define the dtdcontext class
@ -162,7 +201,7 @@ nsDTDContext::nsDTDContext(int aDefaultSize) {
mStyles =new nsTagStack*[aDefaultSize]; mStyles =new nsTagStack*[aDefaultSize];
#endif #endif
mOpenStyles=0; mOpenStyles=0;
nsCRT::zero(mStyles,mTags.mCapacity*sizeof(void*)); nsCRT::zero(mStyles,aDefaultSize*sizeof(void*));
} }
@ -179,41 +218,44 @@ nsDTDContext::~nsDTDContext() {
/** /**
* *
* @update gess7/9/98 * @update gess7/9/98, harishd 04/04/99
*/ */
PRInt32 nsDTDContext::GetCount(void) { PRInt32 nsDTDContext::GetCount(void) {
return mTags.mCount; return mTags.mTags->GetSize();
} }
/** /**
* *
* @update gess7/9/98 * @update gess7/9/98, harishd 04/04/99
*/ */
void nsDTDContext::Push(eHTMLTags aTag) { void nsDTDContext::Push(eHTMLTags aTag) {
if(mTags.mCount>=mTags.mCapacity) {
#ifndef NS_DEBUG #ifndef NS_DEBUG
nsTagStack** tmp2=new nsTagStack*[2*mTags.mCapacity]; NS_PRECONDITION(mTags.mCount<nsTagStack::eStackSize,"TagStack Overflow: DEBUG VERSION!");
nsCRT::zero(tmp2,2*mTags.mCapacity*sizeof(void*));
nsCRT::memcpy(tmp2,mStyles,mTags.mCapacity*sizeof(void*)); if(GetCount()>=aDefaultSize) {
nsTagStack** tmp2=new nsTagStack*[2*aDefaultSize];
nsCRT::zero(tmp2,2*aDefaultSize*sizeof(void*));
nsCRT::memcpy(tmp2,mStyles,aDefaultSize*sizeof(void*));
delete mStyles; delete mStyles;
mStyles=tmp2; mStyles=tmp2;
//mCapacity*=2;
#else
NS_PRECONDITION(mTags.mCount<nsTagStack::eStackSize,"TagStack Overflow: DEBUG VERSION!");
#endif
} }
#endif
mTags.Push(aTag); mTags.Push(aTag);
} }
/** /**
* * @update gess7/9/98, harishd 04/04/99
* @update gess7/9/98
*/ */
eHTMLTags nsDTDContext::Pop() { eHTMLTags nsDTDContext::Pop() {
eHTMLTags result=eHTMLTag_unknown; eHTMLTags result=eHTMLTag_unknown;
if(mTags.mCount>0) { PRInt32 size = GetCount();
#ifndef NS_DEBUG
size = mTags.mCount;
#endif
if(size>0) {
result=mTags.Pop(); result=mTags.Pop();
mStyles[mTags.mCount]=0; size--;
mStyles[size]=0;
} }
return result; return result;
} }

Просмотреть файл

@ -28,125 +28,164 @@
/** /**
* Default constructor * Default constructor
* @update gess9/10/98 * @update harishd 04/04/99
*/ */
nsTagStack::nsTagStack(int aDefaultSize) { nsTagStack::nsTagStack(int aDefaultSize) {
mCapacity=aDefaultSize; mTags =new nsDeque(nsnull);
mCount=0;
#ifndef NS_DEBUG
mTags =new eHTMLTags[mCapacity];
#endif
nsCRT::zero(mTags,mCapacity*sizeof(eHTMLTags));
} }
/** /**
* Default destructor * Default destructor
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
nsTagStack::~nsTagStack() { nsTagStack::~nsTagStack() {
#ifndef NS_DEBUG
delete mTags; delete mTags;
mTags=0;
#endif
mCapacity=mCount=0;
} }
/** /**
* Resets state of stack to be empty. * Resets state of stack to be empty.
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
void nsTagStack::Empty(void) { void nsTagStack::Empty(void) {
mCount=0; mTags->Empty();
} }
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
void nsTagStack::Push(eHTMLTags aTag) { void nsTagStack::Push(eHTMLTags aTag) {
if(mCount>=mCapacity) { nsTags* result = new nsTags();
#ifndef NS_DEBUG result->mTag=aTag;
eHTMLTags* tmp=new eHTMLTags[2*mCapacity]; mTags->Push(result);
nsCRT::zero(tmp,2*mCapacity*sizeof(eHTMLTag_html));
nsCRT::memcpy(tmp,mTags,mCapacity*sizeof(eHTMLTag_html));
delete mTags;
mTags=tmp;
#else
NS_PRECONDITION(mCount<eStackSize,"TagStack Overflow: DEBUG VERSION!");
#endif
}
mTags[mCount++]=aTag;
} }
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
eHTMLTags nsTagStack::Pop() { eHTMLTags nsTagStack::Pop() {
eHTMLTags result=eHTMLTag_unknown; eHTMLTags result=eHTMLTag_unknown;
if(mCount>0) { if(mTags->GetSize() > 0) {
result=mTags[--mCount]; nsTags* t = (nsTags*)mTags->Pop();
mTags[mCount]=eHTMLTag_unknown; result=t->mTag;
delete t;
} }
return result; return result;
} }
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
eHTMLTags nsTagStack::First() const { eHTMLTags nsTagStack::First() const {
if(mCount>0) if(mTags->GetSize() > 0) {
return mTags[0]; nsTags* result = (nsTags*)mTags->Peek();
return result->mTag;
}
return eHTMLTag_unknown; return eHTMLTag_unknown;
} }
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
eHTMLTags nsTagStack::TagAt(PRInt32 anIndex) const { eHTMLTags nsTagStack::TagAt(PRInt32 anIndex) const {
if((anIndex>=0) && (anIndex<mCount)) if((anIndex>=0) && (anIndex<mTags->GetSize())) {
return mTags[anIndex]; nsTags* result = (nsTags*)mTags->ObjectAt(anIndex);
return result->mTag;
}
return eHTMLTag_unknown; return eHTMLTag_unknown;
}
}
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
eHTMLTags nsTagStack::operator[](PRInt32 anIndex) const { eHTMLTags nsTagStack::operator[](PRInt32 anIndex) const {
if((anIndex>=0) && (anIndex<mCount)) if((anIndex>=0) && (anIndex<mTags->GetSize())) {
return mTags[anIndex]; nsTags* result = (nsTags*)mTags->ObjectAt(anIndex);
return result->mTag;
}
return eHTMLTag_unknown; return eHTMLTag_unknown;
} }
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
eHTMLTags nsTagStack::Last() const { eHTMLTags nsTagStack::Last() const {
if(mCount>0) PRInt32 size = mTags->GetSize();
return mTags[mCount-1]; if(size > 0) {
nsTags* result = (nsTags*)mTags->ObjectAt(size - 1);
return result->mTag;
}
return eHTMLTag_unknown; return eHTMLTag_unknown;
} }
/** /**
* *
* @update gess7/9/98 * @update harishd 04/04/99
*/ */
PRInt32 nsTagStack::GetTopmostIndexOf(eHTMLTags aTag) const { PRInt32 nsTagStack::GetTopmostIndexOf(eHTMLTags aTag) const {
int theIndex=0; int theIndex=0;
for(theIndex=mCount-1;theIndex>=0;theIndex--){ nsTags* result;
if(mTags[theIndex]==aTag) for(theIndex=(mTags->GetSize() - 1);theIndex>=0;theIndex--){
result = (nsTags*)mTags->ObjectAt(theIndex);
if(result->mTag==aTag)
return theIndex; return theIndex;
} }
return kNotFound; return kNotFound;
} }
/**
*
* @update harishd 04/04/99
*/
void nsTagStack::SaveToken(CToken* aToken, PRInt32 aID)
{
NS_PRECONDITION(aID <= mTags->GetSize() && aID > -1,"Out of bounds");
if(aToken) {
nsTags* result = (nsTags*)mTags->ObjectAt(aID);
result->mTokenBank->Push(aToken);
}
}
/**
*
* @update harishd 04/04/99
*/
CToken* nsTagStack::RestoreTokenFrom(PRInt32 aID)
{
NS_PRECONDITION(aID <= mTags->GetSize() && aID > -1,"Out of bounds");
if(mTags->GetSize() > 0) {
nsTags* result = (nsTags*)mTags->ObjectAt(aID);
return (CToken*)result->mTokenBank->PopFront();
}
return nsnull;
}
/**
*
* @update harishd 04/04/99
*/
PRInt32 nsTagStack::TokenCountAt(PRInt32 aID)
{
NS_PRECONDITION(aID <= mTags->GetSize(),"Out of bounds");
if(aID < 0)
return kNotFound;
nsTags* result = (nsTags*)mTags->ObjectAt(aID);
return result->mTokenBank->GetSize();
}
/*************************************************************** /***************************************************************
Now define the dtdcontext class Now define the dtdcontext class
@ -162,7 +201,7 @@ nsDTDContext::nsDTDContext(int aDefaultSize) {
mStyles =new nsTagStack*[aDefaultSize]; mStyles =new nsTagStack*[aDefaultSize];
#endif #endif
mOpenStyles=0; mOpenStyles=0;
nsCRT::zero(mStyles,mTags.mCapacity*sizeof(void*)); nsCRT::zero(mStyles,aDefaultSize*sizeof(void*));
} }
@ -179,41 +218,44 @@ nsDTDContext::~nsDTDContext() {
/** /**
* *
* @update gess7/9/98 * @update gess7/9/98, harishd 04/04/99
*/ */
PRInt32 nsDTDContext::GetCount(void) { PRInt32 nsDTDContext::GetCount(void) {
return mTags.mCount; return mTags.mTags->GetSize();
} }
/** /**
* *
* @update gess7/9/98 * @update gess7/9/98, harishd 04/04/99
*/ */
void nsDTDContext::Push(eHTMLTags aTag) { void nsDTDContext::Push(eHTMLTags aTag) {
if(mTags.mCount>=mTags.mCapacity) {
#ifndef NS_DEBUG #ifndef NS_DEBUG
nsTagStack** tmp2=new nsTagStack*[2*mTags.mCapacity]; NS_PRECONDITION(mTags.mCount<nsTagStack::eStackSize,"TagStack Overflow: DEBUG VERSION!");
nsCRT::zero(tmp2,2*mTags.mCapacity*sizeof(void*));
nsCRT::memcpy(tmp2,mStyles,mTags.mCapacity*sizeof(void*)); if(GetCount()>=aDefaultSize) {
nsTagStack** tmp2=new nsTagStack*[2*aDefaultSize];
nsCRT::zero(tmp2,2*aDefaultSize*sizeof(void*));
nsCRT::memcpy(tmp2,mStyles,aDefaultSize*sizeof(void*));
delete mStyles; delete mStyles;
mStyles=tmp2; mStyles=tmp2;
//mCapacity*=2;
#else
NS_PRECONDITION(mTags.mCount<nsTagStack::eStackSize,"TagStack Overflow: DEBUG VERSION!");
#endif
} }
#endif
mTags.Push(aTag); mTags.Push(aTag);
} }
/** /**
* * @update gess7/9/98, harishd 04/04/99
* @update gess7/9/98
*/ */
eHTMLTags nsDTDContext::Pop() { eHTMLTags nsDTDContext::Pop() {
eHTMLTags result=eHTMLTag_unknown; eHTMLTags result=eHTMLTag_unknown;
if(mTags.mCount>0) { PRInt32 size = GetCount();
#ifndef NS_DEBUG
size = mTags.mCount;
#endif
if(size>0) {
result=mTags.Pop(); result=mTags.Pop();
mStyles[mTags.mCount]=0; size--;
mStyles[size]=0;
} }
return result; return result;
} }