removed a bunch of statically constructed objects

This commit is contained in:
rickg%netscape.com 1999-09-19 16:51:08 +00:00
Родитель 73c490c4d3
Коммит 9a251d1c34
20 изменённых файлов: 392 добавлений и 106 удалений

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

@ -506,8 +506,8 @@ PRInt32 CRTFControlWord::GetTokenType() {
}
nsresult CRTFControlWord::Consume(PRUnichar aChar,nsScanner& aScanner) {
static nsString gAlphaChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
static nsAutoString gDigits("-0123456789");
const char* gAlphaChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const char* gDigits="-0123456789";
PRInt32 result=aScanner.ReadWhile(mTextValue,gAlphaChars,PR_TRUE,PR_FALSE);
if(NS_OK==result) {
@ -585,7 +585,7 @@ PRInt32 CRTFContent::GetTokenType() {
*/
nsresult CRTFContent::Consume(PRUnichar aChar,nsScanner& aScanner) {
static nsString textTerminators("\\{}");
static const char* textTerminators="\\{}";
PRInt32 result=aScanner.ReadUntil(mTextValue,textTerminators,PR_FALSE,PR_FALSE);
return result;
}

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

@ -414,7 +414,7 @@ PRInt32 nsDTDContext::TokenCountAt(PRInt32 aID)
* @update gess7/25/98
* @param
*/
CTokenRecycler::CTokenRecycler() : nsITokenRecycler() {
CTokenRecycler::CTokenRecycler() : nsITokenRecycler(),mEmpty("") {
int i=0;
for(i=0;i<eToken_last-1;i++) {
mTokenCache[i]=new nsDeque(new CTokenDeallocator());
@ -523,9 +523,8 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag)
CToken* result=(CToken*)mTokenCache[aType-1]->Pop();
static nsAutoString theEmpty;
if(result) {
result->Reinitialize(aTag,theEmpty);
result->Reinitialize(aTag,mEmpty);
}
else {
#ifdef NS_DEBUG
@ -539,10 +538,10 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag)
case eToken_entity: result=new CEntityToken(); break;
case eToken_whitespace: result=new CWhitespaceToken(); break;
case eToken_newline: result=new CNewlineToken(); break;
case eToken_text: result=new CTextToken(theEmpty); break;
case eToken_text: result=new CTextToken(mEmpty); break;
case eToken_script: result=new CScriptToken(); break;
case eToken_style: result=new CStyleToken(); break;
case eToken_skippedcontent: result=new CSkippedContentToken(theEmpty); break;
case eToken_skippedcontent: result=new CSkippedContentToken(mEmpty); break;
case eToken_instruction: result=new CInstructionToken(); break;
case eToken_cdatasection: result=new CCDATASectionToken(); break;
case eToken_error: result=new CErrorToken(); break;

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

@ -158,6 +158,7 @@ public:
protected:
nsDeque* mTokenCache[eToken_last-1];
nsString mEmpty;
#ifdef NS_DEBUG
int mTotals[eToken_last-1];
#endif

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

@ -184,8 +184,11 @@ nsHTMLEntities::UnicodeToEntity(PRInt32 aUnicode)
return found->mStr;
}
}
static const nsCString kNullStr;
return kNullStr;
static const nsCString* kNullStr=0;
if(!kNullStr) {
kNullStr=new nsCString("");
}
return *kNullStr;
}

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

@ -132,8 +132,10 @@ nsHTMLTags::GetStringValue(nsHTMLTag aTag)
return gTagArray[aTag - 1].mStr;
}
else {
static const nsCString kNullStr;
return kNullStr;
static const nsCString* kNullStr=0;
if(!kNullStr)
kNullStr=new nsCString("");
return *kNullStr;
}
}

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

@ -146,6 +146,14 @@ void nsHTMLTokenizer::AddToken(CToken*& aToken,nsresult aResult,nsDeque& aDeque,
* @return ptr to recycler (or null)
*/
nsITokenRecycler* nsHTMLTokenizer::GetTokenRecycler(void) {
#if 0
//let's move to this once we eliminate the leaking of tokens...
static CTokenRecycler* gTokenRecycler=0;
if(!gTokenRecycler)
gTokenRecycler=new CTokenRecycler();
return gTokenRecycler;
#endif
static CTokenRecycler gTokenRecycler;
return (nsITokenRecycler*)&gTokenRecycler;
}

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

@ -33,6 +33,8 @@
static const char* gUserdefined = "userdefined";
static const char* gIdentChars="-0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
static const char* gNumChars="0123456789ABCDEFabcdef";
const PRInt32 kMAXNAMELEN=10;
@ -192,17 +194,6 @@ PRBool CStartToken::IsEmpty(void) {
return mEmpty;
}
static
nsString& GetIdentChars(void) {
static nsString gIdentChars("-0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz");
return gIdentChars;
}
static
nsString& GetNumericChars(void) {
static nsString gNumChars("0123456789ABCDEFabcdef");
return gNumChars;
}
/*
* Consume the identifier portion of the start tag
@ -220,7 +211,7 @@ nsresult CStartToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
//NOTE: We don't Consume the tag attributes here, nor do we eat the ">"
mTextValue=aChar;
nsresult result=aScanner.ReadWhile(mTextValue,GetIdentChars(),PR_TRUE,PR_FALSE);
nsresult result=aScanner.ReadWhile(mTextValue,gIdentChars,PR_TRUE,PR_FALSE);
mTypeID = nsHTMLTags::LookupTag(mTextValue);
//Good. Now, let's skip whitespace after the identifier,
@ -448,12 +439,12 @@ PRInt32 CTextToken::GetTokenType(void) {
* @return error result
*/
nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
static nsAutoString terminals("&<\r\n");
static const char* theTerminals="&<\r\n";
nsresult result=NS_OK;
PRBool done=PR_FALSE;
while((NS_OK==result) && (!done)) {
result=aScanner.ReadUntil(mTextValue,terminals,PR_FALSE,PR_FALSE);
result=aScanner.ReadUntil(mTextValue,theTerminals,PR_FALSE,PR_FALSE);
if(NS_OK==result) {
result=aScanner.Peek(aChar);
if((kCR==aChar) && (NS_OK==result)) {
@ -502,7 +493,6 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
//If we find either, just eat them. If we find text or a tag, then go to the
//target endtag, or the start of another comment.
static nsAutoString theWhitespace2("\b\t ");
PRInt32 termStrLen=aTerminalString.Length();
while((!done) && (NS_OK==result)) {
@ -527,7 +517,7 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
result=aScanner.ReadUntil(mTextValue,kGreaterThan,PR_TRUE);
}
}
else if(0<=theWhitespace2.BinarySearch(aChar)) {
else if(('\b'==theChar) || ('\t'==theChar) || (' '==theChar)) {
static CWhitespaceToken theWS;
result=theWS.Consume(aChar,aScanner);
if(NS_OK==result) {
@ -609,12 +599,12 @@ PRInt32 CCDATASectionToken::GetTokenType(void) {
* @return error result
*/
nsresult CCDATASectionToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
static nsAutoString terminals("]\r");
static const char* theTerminals="]\r";
nsresult result=NS_OK;
PRBool done=PR_FALSE;
while((NS_OK==result) && (!done)) {
result=aScanner.ReadUntil(mTextValue,terminals,PR_FALSE,PR_FALSE);
result=aScanner.ReadUntil(mTextValue,theTerminals,PR_FALSE,PR_FALSE);
if(NS_OK==result) {
result=aScanner.Peek(aChar);
if((kCR==aChar) && (NS_OK==result)) {
@ -698,7 +688,7 @@ CCommentToken::CCommentToken(const nsString& aName) : CHTMLToken(aName) {
*/
static
nsresult ConsumeStrictComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString) {
static nsAutoString gMinus("-");
static const char* gMinus="-";
nsresult result=NS_OK;
/*********************************************************
@ -767,11 +757,7 @@ nsresult ConsumeStrictComment(PRUnichar aChar, nsScanner& aScanner,nsString& aSt
*/
static
nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString) {
static nsAutoString gEdibles("!-");
static nsAutoString gMinus("-");
static nsAutoString gWhitespace("\b\t\n\r ");
static nsAutoString gDfltEndComment("-->");
nsresult result=NS_OK;
@ -794,6 +780,9 @@ nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString)
if(NS_OK==result) {
if(kMinus==aChar) {
//in this case, we're reading a long-form comment <-- xxx -->
nsAutoString gDfltEndComment("-->");
aString+=aChar;
PRInt32 findpos=kNotFound;
while((kNotFound==findpos) && (NS_OK==result)) {
@ -948,8 +937,10 @@ PRInt32 CNewlineToken::GetTokenType(void) {
* @return nsString reference to internal string value
*/
nsString& CNewlineToken::GetStringValueXXX(void) {
static nsAutoString theStr("\n");
return theStr;
static nsString* theStr=0;
if(!theStr)
theStr=new nsString("\n");
return *theStr;
}
/*
@ -1151,8 +1142,8 @@ nsresult ConsumeQuotedString(PRUnichar aChar,nsString& aString,nsScanner& aScann
*/
static
nsresult ConsumeAttributeValueText(PRUnichar,nsString& aString,nsScanner& aScanner){
static nsAutoString terminals("\b\t\n\r >");
nsresult result=aScanner.ReadUntil(aString,terminals,PR_FALSE,PR_FALSE);
static const char* theTerminals="\b\t\n\r >";
nsresult result=aScanner.ReadUntil(aString,theTerminals,PR_FALSE,PR_FALSE);
//Let's force quotes if either the first or last char is quoted.
PRUnichar theLast=aString.Last();
@ -1205,15 +1196,16 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
result=aScanner.GetChar(aChar); //skip the hash sign...
if(NS_OK==result) {
mTextKey=aChar;
static nsAutoString gDigits("0123456789");
static const char* gDigits="0123456789";
result=aScanner.ReadWhile(mTextKey,gDigits,PR_TRUE,PR_FALSE);
}
}
else {
//If you're here, handle an unquoted key.
//Don't forget to reduce entities inline!
static nsAutoString terminals("\b\t\n\r \"<=>");
result=aScanner.ReadUntil(mTextKey,terminals,PR_TRUE,PR_FALSE);
static const char* theTerminals="\b\t\n\r \"<=>";
result=aScanner.ReadUntil(mTextKey,theTerminals,PR_TRUE,PR_FALSE);
}
//now it's time to Consume the (optional) value...
@ -1355,7 +1347,7 @@ PRInt32 CWhitespaceToken::GetTokenType(void) {
nsresult CWhitespaceToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
mTextValue=aChar;
static nsAutoString theWhitespace("\b\t ");
static const char* theWhitespace="\b\t ";
nsresult result=aScanner.ReadWhile(mTextValue,theWhitespace,PR_FALSE,PR_FALSE);
if(NS_OK==result) {
mTextValue.StripChars("\r");
@ -1468,10 +1460,10 @@ PRInt32 CEntityToken::ConsumeEntity(PRUnichar aChar,nsString& aString,nsScanner&
aString+=theChar;
}
if(NS_OK==result){
result=aScanner.ReadWhile(aString,GetNumericChars(),PR_TRUE,PR_FALSE);
result=aScanner.ReadWhile(aString,gNumChars,PR_TRUE,PR_FALSE);
}
}
else result=aScanner.ReadWhile(aString,GetIdentChars(),PR_TRUE,PR_FALSE);
else result=aScanner.ReadWhile(aString,gIdentChars,PR_TRUE,PR_FALSE);
if(NS_OK==result) {
result=aScanner.Peek(theChar);
if(NS_OK==result) {
@ -1721,8 +1713,6 @@ nsresult CSkippedContentToken::Consume(PRUnichar aChar,nsScanner& aScanner) {
//If we find either, just eat them. If we find text or a tag, then go to the
//target endtag, or the start of another comment.
static nsAutoString theWhitespace2("\b\t ");
while((!done) && (NS_OK==result)) {
result=aScanner.GetChar(aChar);
if((NS_OK==result) && (kLessThan==aChar)) {
@ -1743,7 +1733,7 @@ nsresult CSkippedContentToken::Consume(PRUnichar aChar,nsScanner& aScanner) {
result=aScanner.ReadUntil(temp,kGreaterThan,PR_TRUE);
}
}
else if(0<=theWhitespace2.BinarySearch(aChar)) {
else if(('\b'==theChar) || ('\t'==theChar) || (' '==theChar)) {
static CWhitespaceToken theWS;
result=theWS.Consume(aChar,aScanner);
if(NS_OK==result) {

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

@ -28,9 +28,11 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kClassIID, NS_PARSER_NODE_IID);
static NS_DEFINE_IID(kIParserNodeIID, NS_IPARSER_NODE_IID);
nsAutoString& GetEmptyString() {
static nsAutoString theEmptyString("");
return theEmptyString;
nsString& GetEmptyString() {
static nsString* gEmptyStr=0;
if(!gEmptyStr)
gEmptyStr=new nsString("");
return *gEmptyStr;
}
/**

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

@ -430,8 +430,12 @@ nsresult nsScanner::PutBack(PRUnichar aChar) {
* @return error status
*/
nsresult nsScanner::SkipWhitespace(void) {
static nsAutoString chars(" \n\r\t\b");
return SkipOver(chars);
static const char* gSpaces=" \n\r\t\b";
int len=strlen(gSpaces);
CBufDescriptor buf(gSpaces,PR_TRUE,len+1,len);
nsAutoString theWS(buf);
return SkipOver(theWS);
}
/**
@ -561,6 +565,72 @@ nsresult nsScanner::ReadWhile(nsString& aString,
return result;
}
/**
* Consume chars as long as they are <i>in</i> the
* given validSet of input chars.
*
* @update gess 3/25/98
* @param aString will contain the result of this method
* @param aValidSet is an ordered string that contains the
* valid characters
* @return error code
*/
nsresult nsScanner::ReadWhile(nsString& aString,
nsCString& aValidSet,
PRBool anOrderedSet,
PRBool addTerminal){
NS_ASSERTION(((PR_FALSE==anOrderedSet) || aValidSet.IsOrdered()),kUnorderedStringError);
PRUnichar theChar=0;
nsresult result=NS_OK;
while(NS_OK==result) {
result=GetChar(theChar);
if(NS_OK==result) {
PRInt32 pos=(anOrderedSet) ? aValidSet.BinarySearch(theChar) : aValidSet.FindChar(theChar);
if(kNotFound==pos) {
if(addTerminal)
aString+=theChar;
else PutBack(theChar);
break;
}
else aString+=theChar;
}
}
return result;
}
/**
* Consume chars as long as they are <i>in</i> the
* given validSet of input chars.
*
* @update gess 3/25/98
* @param aString will contain the result of this method
* @param anInputSet contains the legal input chars
* valid characters
* @return error code
*/
nsresult nsScanner::ReadWhile(nsString& aString,
const char* anInputSet,
PRBool anOrderedSet,
PRBool addTerminal)
{
nsresult result=NS_OK;
if(anInputSet) {
PRInt32 len=nsCRT::strlen(anInputSet);
if(0<len) {
CBufDescriptor buf(anInputSet,PR_TRUE,len+1,len);
nsCAutoString theSet(buf);
result=ReadWhile(aString,theSet,anOrderedSet,addTerminal);
} //if
}//if
return result;
}
/**
* Consume characters until you encounter one contained in given
* input set.
@ -597,6 +667,70 @@ nsresult nsScanner::ReadUntil(nsString& aString,
return result;
}
/**
* Consume characters until you encounter one contained in given
* input set.
*
* @update gess 3/25/98
* @param aString will contain the result of this method
* @param aTerminalSet is an ordered string that contains
* the set of INVALID characters
* @return error code
*/
nsresult nsScanner::ReadUntil(nsString& aString,
nsCString& aTerminalSet,
PRBool anOrderedSet,
PRBool addTerminal){
NS_ASSERTION(((PR_FALSE==anOrderedSet) || aTerminalSet.IsOrdered()),kUnorderedStringError);
PRUnichar theChar=0;
nsresult result=NS_OK;
while(NS_OK == result) {
result=GetChar(theChar);
if(NS_OK==result) {
PRInt32 pos=(anOrderedSet) ? aTerminalSet.BinarySearch(theChar) : aTerminalSet.FindChar(theChar);
if(kNotFound!=pos) {
if(addTerminal)
aString+=theChar;
else PutBack(theChar);
break;
}
else aString+=theChar;
}
}
return result;
}
/**
* Consume characters until you encounter one contained in given
* input set.
*
* @update gess 3/25/98
* @param aString will contain the result of this method
* @param aTerminalSet is an ordered string that contains
* the set of INVALID characters
* @return error code
*/
nsresult nsScanner::ReadUntil(nsString& aString,
const char* aTerminalSet,
PRBool anOrderedSet,
PRBool addTerminal)
{
nsresult result=NS_OK;
if(aTerminalSet) {
PRInt32 len=nsCRT::strlen(aTerminalSet);
if(0<len) {
CBufDescriptor buf(aTerminalSet,PR_TRUE,len+1,len);
nsCAutoString theSet(buf);
result=ReadUntil(aString,theSet,anOrderedSet,addTerminal);
} //if
}//if
return result;
}
/**
* Consumes chars until you see the given terminalChar

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

@ -185,6 +185,8 @@ class nsScanner {
* @return error code
*/
nsresult ReadUntil(nsString& aString,nsString& aTermSet,PRBool anOrderedSet,PRBool addTerminal);
nsresult ReadUntil(nsString& aString,nsCString& aTermSet,PRBool anOrderedSet,PRBool addTerminal);
nsresult ReadUntil(nsString& aString,const char* aTermSet,PRBool anOrderedSet,PRBool addTerminal);
/**
* Consume characters while they're members of anInputSet
@ -196,6 +198,8 @@ class nsScanner {
* @return error code
*/
nsresult ReadWhile(nsString& aString,nsString& anInputSet,PRBool anOrderedSet,PRBool addTerminal);
nsresult ReadWhile(nsString& aString,nsCString& anInputSet,PRBool anOrderedSet,PRBool addTerminal);
nsresult ReadWhile(nsString& aString,const char* anInputSet, PRBool anOrderedSet, PRBool addTerminal);
/**
* Records current offset position in input stream. This allows us

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

@ -506,8 +506,8 @@ PRInt32 CRTFControlWord::GetTokenType() {
}
nsresult CRTFControlWord::Consume(PRUnichar aChar,nsScanner& aScanner) {
static nsString gAlphaChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
static nsAutoString gDigits("-0123456789");
const char* gAlphaChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const char* gDigits="-0123456789";
PRInt32 result=aScanner.ReadWhile(mTextValue,gAlphaChars,PR_TRUE,PR_FALSE);
if(NS_OK==result) {
@ -585,7 +585,7 @@ PRInt32 CRTFContent::GetTokenType() {
*/
nsresult CRTFContent::Consume(PRUnichar aChar,nsScanner& aScanner) {
static nsString textTerminators("\\{}");
static const char* textTerminators="\\{}";
PRInt32 result=aScanner.ReadUntil(mTextValue,textTerminators,PR_FALSE,PR_FALSE);
return result;
}

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

@ -414,7 +414,7 @@ PRInt32 nsDTDContext::TokenCountAt(PRInt32 aID)
* @update gess7/25/98
* @param
*/
CTokenRecycler::CTokenRecycler() : nsITokenRecycler() {
CTokenRecycler::CTokenRecycler() : nsITokenRecycler(),mEmpty("") {
int i=0;
for(i=0;i<eToken_last-1;i++) {
mTokenCache[i]=new nsDeque(new CTokenDeallocator());
@ -523,9 +523,8 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag)
CToken* result=(CToken*)mTokenCache[aType-1]->Pop();
static nsAutoString theEmpty;
if(result) {
result->Reinitialize(aTag,theEmpty);
result->Reinitialize(aTag,mEmpty);
}
else {
#ifdef NS_DEBUG
@ -539,10 +538,10 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag)
case eToken_entity: result=new CEntityToken(); break;
case eToken_whitespace: result=new CWhitespaceToken(); break;
case eToken_newline: result=new CNewlineToken(); break;
case eToken_text: result=new CTextToken(theEmpty); break;
case eToken_text: result=new CTextToken(mEmpty); break;
case eToken_script: result=new CScriptToken(); break;
case eToken_style: result=new CStyleToken(); break;
case eToken_skippedcontent: result=new CSkippedContentToken(theEmpty); break;
case eToken_skippedcontent: result=new CSkippedContentToken(mEmpty); break;
case eToken_instruction: result=new CInstructionToken(); break;
case eToken_cdatasection: result=new CCDATASectionToken(); break;
case eToken_error: result=new CErrorToken(); break;

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

@ -158,6 +158,7 @@ public:
protected:
nsDeque* mTokenCache[eToken_last-1];
nsString mEmpty;
#ifdef NS_DEBUG
int mTotals[eToken_last-1];
#endif

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

@ -184,8 +184,11 @@ nsHTMLEntities::UnicodeToEntity(PRInt32 aUnicode)
return found->mStr;
}
}
static const nsCString kNullStr;
return kNullStr;
static const nsCString* kNullStr=0;
if(!kNullStr) {
kNullStr=new nsCString("");
}
return *kNullStr;
}

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

@ -132,8 +132,10 @@ nsHTMLTags::GetStringValue(nsHTMLTag aTag)
return gTagArray[aTag - 1].mStr;
}
else {
static const nsCString kNullStr;
return kNullStr;
static const nsCString* kNullStr=0;
if(!kNullStr)
kNullStr=new nsCString("");
return *kNullStr;
}
}

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

@ -146,6 +146,14 @@ void nsHTMLTokenizer::AddToken(CToken*& aToken,nsresult aResult,nsDeque& aDeque,
* @return ptr to recycler (or null)
*/
nsITokenRecycler* nsHTMLTokenizer::GetTokenRecycler(void) {
#if 0
//let's move to this once we eliminate the leaking of tokens...
static CTokenRecycler* gTokenRecycler=0;
if(!gTokenRecycler)
gTokenRecycler=new CTokenRecycler();
return gTokenRecycler;
#endif
static CTokenRecycler gTokenRecycler;
return (nsITokenRecycler*)&gTokenRecycler;
}

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

@ -33,6 +33,8 @@
static const char* gUserdefined = "userdefined";
static const char* gIdentChars="-0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
static const char* gNumChars="0123456789ABCDEFabcdef";
const PRInt32 kMAXNAMELEN=10;
@ -192,17 +194,6 @@ PRBool CStartToken::IsEmpty(void) {
return mEmpty;
}
static
nsString& GetIdentChars(void) {
static nsString gIdentChars("-0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz");
return gIdentChars;
}
static
nsString& GetNumericChars(void) {
static nsString gNumChars("0123456789ABCDEFabcdef");
return gNumChars;
}
/*
* Consume the identifier portion of the start tag
@ -220,7 +211,7 @@ nsresult CStartToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
//NOTE: We don't Consume the tag attributes here, nor do we eat the ">"
mTextValue=aChar;
nsresult result=aScanner.ReadWhile(mTextValue,GetIdentChars(),PR_TRUE,PR_FALSE);
nsresult result=aScanner.ReadWhile(mTextValue,gIdentChars,PR_TRUE,PR_FALSE);
mTypeID = nsHTMLTags::LookupTag(mTextValue);
//Good. Now, let's skip whitespace after the identifier,
@ -448,12 +439,12 @@ PRInt32 CTextToken::GetTokenType(void) {
* @return error result
*/
nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
static nsAutoString terminals("&<\r\n");
static const char* theTerminals="&<\r\n";
nsresult result=NS_OK;
PRBool done=PR_FALSE;
while((NS_OK==result) && (!done)) {
result=aScanner.ReadUntil(mTextValue,terminals,PR_FALSE,PR_FALSE);
result=aScanner.ReadUntil(mTextValue,theTerminals,PR_FALSE,PR_FALSE);
if(NS_OK==result) {
result=aScanner.Peek(aChar);
if((kCR==aChar) && (NS_OK==result)) {
@ -502,7 +493,6 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
//If we find either, just eat them. If we find text or a tag, then go to the
//target endtag, or the start of another comment.
static nsAutoString theWhitespace2("\b\t ");
PRInt32 termStrLen=aTerminalString.Length();
while((!done) && (NS_OK==result)) {
@ -527,7 +517,7 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
result=aScanner.ReadUntil(mTextValue,kGreaterThan,PR_TRUE);
}
}
else if(0<=theWhitespace2.BinarySearch(aChar)) {
else if(('\b'==theChar) || ('\t'==theChar) || (' '==theChar)) {
static CWhitespaceToken theWS;
result=theWS.Consume(aChar,aScanner);
if(NS_OK==result) {
@ -609,12 +599,12 @@ PRInt32 CCDATASectionToken::GetTokenType(void) {
* @return error result
*/
nsresult CCDATASectionToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
static nsAutoString terminals("]\r");
static const char* theTerminals="]\r";
nsresult result=NS_OK;
PRBool done=PR_FALSE;
while((NS_OK==result) && (!done)) {
result=aScanner.ReadUntil(mTextValue,terminals,PR_FALSE,PR_FALSE);
result=aScanner.ReadUntil(mTextValue,theTerminals,PR_FALSE,PR_FALSE);
if(NS_OK==result) {
result=aScanner.Peek(aChar);
if((kCR==aChar) && (NS_OK==result)) {
@ -698,7 +688,7 @@ CCommentToken::CCommentToken(const nsString& aName) : CHTMLToken(aName) {
*/
static
nsresult ConsumeStrictComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString) {
static nsAutoString gMinus("-");
static const char* gMinus="-";
nsresult result=NS_OK;
/*********************************************************
@ -767,11 +757,7 @@ nsresult ConsumeStrictComment(PRUnichar aChar, nsScanner& aScanner,nsString& aSt
*/
static
nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString) {
static nsAutoString gEdibles("!-");
static nsAutoString gMinus("-");
static nsAutoString gWhitespace("\b\t\n\r ");
static nsAutoString gDfltEndComment("-->");
nsresult result=NS_OK;
@ -794,6 +780,9 @@ nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString)
if(NS_OK==result) {
if(kMinus==aChar) {
//in this case, we're reading a long-form comment <-- xxx -->
nsAutoString gDfltEndComment("-->");
aString+=aChar;
PRInt32 findpos=kNotFound;
while((kNotFound==findpos) && (NS_OK==result)) {
@ -948,8 +937,10 @@ PRInt32 CNewlineToken::GetTokenType(void) {
* @return nsString reference to internal string value
*/
nsString& CNewlineToken::GetStringValueXXX(void) {
static nsAutoString theStr("\n");
return theStr;
static nsString* theStr=0;
if(!theStr)
theStr=new nsString("\n");
return *theStr;
}
/*
@ -1151,8 +1142,8 @@ nsresult ConsumeQuotedString(PRUnichar aChar,nsString& aString,nsScanner& aScann
*/
static
nsresult ConsumeAttributeValueText(PRUnichar,nsString& aString,nsScanner& aScanner){
static nsAutoString terminals("\b\t\n\r >");
nsresult result=aScanner.ReadUntil(aString,terminals,PR_FALSE,PR_FALSE);
static const char* theTerminals="\b\t\n\r >";
nsresult result=aScanner.ReadUntil(aString,theTerminals,PR_FALSE,PR_FALSE);
//Let's force quotes if either the first or last char is quoted.
PRUnichar theLast=aString.Last();
@ -1205,15 +1196,16 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
result=aScanner.GetChar(aChar); //skip the hash sign...
if(NS_OK==result) {
mTextKey=aChar;
static nsAutoString gDigits("0123456789");
static const char* gDigits="0123456789";
result=aScanner.ReadWhile(mTextKey,gDigits,PR_TRUE,PR_FALSE);
}
}
else {
//If you're here, handle an unquoted key.
//Don't forget to reduce entities inline!
static nsAutoString terminals("\b\t\n\r \"<=>");
result=aScanner.ReadUntil(mTextKey,terminals,PR_TRUE,PR_FALSE);
static const char* theTerminals="\b\t\n\r \"<=>";
result=aScanner.ReadUntil(mTextKey,theTerminals,PR_TRUE,PR_FALSE);
}
//now it's time to Consume the (optional) value...
@ -1355,7 +1347,7 @@ PRInt32 CWhitespaceToken::GetTokenType(void) {
nsresult CWhitespaceToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
mTextValue=aChar;
static nsAutoString theWhitespace("\b\t ");
static const char* theWhitespace="\b\t ";
nsresult result=aScanner.ReadWhile(mTextValue,theWhitespace,PR_FALSE,PR_FALSE);
if(NS_OK==result) {
mTextValue.StripChars("\r");
@ -1468,10 +1460,10 @@ PRInt32 CEntityToken::ConsumeEntity(PRUnichar aChar,nsString& aString,nsScanner&
aString+=theChar;
}
if(NS_OK==result){
result=aScanner.ReadWhile(aString,GetNumericChars(),PR_TRUE,PR_FALSE);
result=aScanner.ReadWhile(aString,gNumChars,PR_TRUE,PR_FALSE);
}
}
else result=aScanner.ReadWhile(aString,GetIdentChars(),PR_TRUE,PR_FALSE);
else result=aScanner.ReadWhile(aString,gIdentChars,PR_TRUE,PR_FALSE);
if(NS_OK==result) {
result=aScanner.Peek(theChar);
if(NS_OK==result) {
@ -1721,8 +1713,6 @@ nsresult CSkippedContentToken::Consume(PRUnichar aChar,nsScanner& aScanner) {
//If we find either, just eat them. If we find text or a tag, then go to the
//target endtag, or the start of another comment.
static nsAutoString theWhitespace2("\b\t ");
while((!done) && (NS_OK==result)) {
result=aScanner.GetChar(aChar);
if((NS_OK==result) && (kLessThan==aChar)) {
@ -1743,7 +1733,7 @@ nsresult CSkippedContentToken::Consume(PRUnichar aChar,nsScanner& aScanner) {
result=aScanner.ReadUntil(temp,kGreaterThan,PR_TRUE);
}
}
else if(0<=theWhitespace2.BinarySearch(aChar)) {
else if(('\b'==theChar) || ('\t'==theChar) || (' '==theChar)) {
static CWhitespaceToken theWS;
result=theWS.Consume(aChar,aScanner);
if(NS_OK==result) {

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

@ -28,9 +28,11 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kClassIID, NS_PARSER_NODE_IID);
static NS_DEFINE_IID(kIParserNodeIID, NS_IPARSER_NODE_IID);
nsAutoString& GetEmptyString() {
static nsAutoString theEmptyString("");
return theEmptyString;
nsString& GetEmptyString() {
static nsString* gEmptyStr=0;
if(!gEmptyStr)
gEmptyStr=new nsString("");
return *gEmptyStr;
}
/**

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

@ -430,8 +430,12 @@ nsresult nsScanner::PutBack(PRUnichar aChar) {
* @return error status
*/
nsresult nsScanner::SkipWhitespace(void) {
static nsAutoString chars(" \n\r\t\b");
return SkipOver(chars);
static const char* gSpaces=" \n\r\t\b";
int len=strlen(gSpaces);
CBufDescriptor buf(gSpaces,PR_TRUE,len+1,len);
nsAutoString theWS(buf);
return SkipOver(theWS);
}
/**
@ -561,6 +565,72 @@ nsresult nsScanner::ReadWhile(nsString& aString,
return result;
}
/**
* Consume chars as long as they are <i>in</i> the
* given validSet of input chars.
*
* @update gess 3/25/98
* @param aString will contain the result of this method
* @param aValidSet is an ordered string that contains the
* valid characters
* @return error code
*/
nsresult nsScanner::ReadWhile(nsString& aString,
nsCString& aValidSet,
PRBool anOrderedSet,
PRBool addTerminal){
NS_ASSERTION(((PR_FALSE==anOrderedSet) || aValidSet.IsOrdered()),kUnorderedStringError);
PRUnichar theChar=0;
nsresult result=NS_OK;
while(NS_OK==result) {
result=GetChar(theChar);
if(NS_OK==result) {
PRInt32 pos=(anOrderedSet) ? aValidSet.BinarySearch(theChar) : aValidSet.FindChar(theChar);
if(kNotFound==pos) {
if(addTerminal)
aString+=theChar;
else PutBack(theChar);
break;
}
else aString+=theChar;
}
}
return result;
}
/**
* Consume chars as long as they are <i>in</i> the
* given validSet of input chars.
*
* @update gess 3/25/98
* @param aString will contain the result of this method
* @param anInputSet contains the legal input chars
* valid characters
* @return error code
*/
nsresult nsScanner::ReadWhile(nsString& aString,
const char* anInputSet,
PRBool anOrderedSet,
PRBool addTerminal)
{
nsresult result=NS_OK;
if(anInputSet) {
PRInt32 len=nsCRT::strlen(anInputSet);
if(0<len) {
CBufDescriptor buf(anInputSet,PR_TRUE,len+1,len);
nsCAutoString theSet(buf);
result=ReadWhile(aString,theSet,anOrderedSet,addTerminal);
} //if
}//if
return result;
}
/**
* Consume characters until you encounter one contained in given
* input set.
@ -597,6 +667,70 @@ nsresult nsScanner::ReadUntil(nsString& aString,
return result;
}
/**
* Consume characters until you encounter one contained in given
* input set.
*
* @update gess 3/25/98
* @param aString will contain the result of this method
* @param aTerminalSet is an ordered string that contains
* the set of INVALID characters
* @return error code
*/
nsresult nsScanner::ReadUntil(nsString& aString,
nsCString& aTerminalSet,
PRBool anOrderedSet,
PRBool addTerminal){
NS_ASSERTION(((PR_FALSE==anOrderedSet) || aTerminalSet.IsOrdered()),kUnorderedStringError);
PRUnichar theChar=0;
nsresult result=NS_OK;
while(NS_OK == result) {
result=GetChar(theChar);
if(NS_OK==result) {
PRInt32 pos=(anOrderedSet) ? aTerminalSet.BinarySearch(theChar) : aTerminalSet.FindChar(theChar);
if(kNotFound!=pos) {
if(addTerminal)
aString+=theChar;
else PutBack(theChar);
break;
}
else aString+=theChar;
}
}
return result;
}
/**
* Consume characters until you encounter one contained in given
* input set.
*
* @update gess 3/25/98
* @param aString will contain the result of this method
* @param aTerminalSet is an ordered string that contains
* the set of INVALID characters
* @return error code
*/
nsresult nsScanner::ReadUntil(nsString& aString,
const char* aTerminalSet,
PRBool anOrderedSet,
PRBool addTerminal)
{
nsresult result=NS_OK;
if(aTerminalSet) {
PRInt32 len=nsCRT::strlen(aTerminalSet);
if(0<len) {
CBufDescriptor buf(aTerminalSet,PR_TRUE,len+1,len);
nsCAutoString theSet(buf);
result=ReadUntil(aString,theSet,anOrderedSet,addTerminal);
} //if
}//if
return result;
}
/**
* Consumes chars until you see the given terminalChar

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

@ -185,6 +185,8 @@ class nsScanner {
* @return error code
*/
nsresult ReadUntil(nsString& aString,nsString& aTermSet,PRBool anOrderedSet,PRBool addTerminal);
nsresult ReadUntil(nsString& aString,nsCString& aTermSet,PRBool anOrderedSet,PRBool addTerminal);
nsresult ReadUntil(nsString& aString,const char* aTermSet,PRBool anOrderedSet,PRBool addTerminal);
/**
* Consume characters while they're members of anInputSet
@ -196,6 +198,8 @@ class nsScanner {
* @return error code
*/
nsresult ReadWhile(nsString& aString,nsString& anInputSet,PRBool anOrderedSet,PRBool addTerminal);
nsresult ReadWhile(nsString& aString,nsCString& anInputSet,PRBool anOrderedSet,PRBool addTerminal);
nsresult ReadWhile(nsString& aString,const char* anInputSet, PRBool anOrderedSet, PRBool addTerminal);
/**
* Records current offset position in input stream. This allows us