diff --git a/htmlparser/src/CRtfDTD.cpp b/htmlparser/src/CRtfDTD.cpp
index c0c4b7d617a..58c6247fb3f 100644
--- a/htmlparser/src/CRtfDTD.cpp
+++ b/htmlparser/src/CRtfDTD.cpp
@@ -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;
}
diff --git a/htmlparser/src/nsDTDUtils.cpp b/htmlparser/src/nsDTDUtils.cpp
index 4047f8c9048..5fc888becf7 100644
--- a/htmlparser/src/nsDTDUtils.cpp
+++ b/htmlparser/src/nsDTDUtils.cpp
@@ -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;iPop();
- 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;
diff --git a/htmlparser/src/nsDTDUtils.h b/htmlparser/src/nsDTDUtils.h
index 00b11327c10..781c7c741f0 100644
--- a/htmlparser/src/nsDTDUtils.h
+++ b/htmlparser/src/nsDTDUtils.h
@@ -158,6 +158,7 @@ public:
protected:
nsDeque* mTokenCache[eToken_last-1];
+ nsString mEmpty;
#ifdef NS_DEBUG
int mTotals[eToken_last-1];
#endif
diff --git a/htmlparser/src/nsHTMLEntities.cpp b/htmlparser/src/nsHTMLEntities.cpp
index 08ebc007245..d25688b6b7b 100644
--- a/htmlparser/src/nsHTMLEntities.cpp
+++ b/htmlparser/src/nsHTMLEntities.cpp
@@ -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;
}
diff --git a/htmlparser/src/nsHTMLTags.cpp b/htmlparser/src/nsHTMLTags.cpp
index e56f16a221c..008e8d3b2fa 100644
--- a/htmlparser/src/nsHTMLTags.cpp
+++ b/htmlparser/src/nsHTMLTags.cpp
@@ -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;
}
}
diff --git a/htmlparser/src/nsHTMLTokenizer.cpp b/htmlparser/src/nsHTMLTokenizer.cpp
index b47df13c88b..297c818faf5 100644
--- a/htmlparser/src/nsHTMLTokenizer.cpp
+++ b/htmlparser/src/nsHTMLTokenizer.cpp
@@ -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;
}
diff --git a/htmlparser/src/nsHTMLTokens.cpp b/htmlparser/src/nsHTMLTokens.cpp
index 2d1cf1b1571..c517d15d43f 100644
--- a/htmlparser/src/nsHTMLTokens.cpp
+++ b/htmlparser/src/nsHTMLTokens.cpp
@@ -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) {
diff --git a/htmlparser/src/nsParserNode.cpp b/htmlparser/src/nsParserNode.cpp
index 213fa5e7a73..a30cabc31d8 100644
--- a/htmlparser/src/nsParserNode.cpp
+++ b/htmlparser/src/nsParserNode.cpp
@@ -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;
}
/**
diff --git a/htmlparser/src/nsScanner.cpp b/htmlparser/src/nsScanner.cpp
index 69310a70eb6..46615455cc0 100644
--- a/htmlparser/src/nsScanner.cpp
+++ b/htmlparser/src/nsScanner.cpp
@@ -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 in 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 in 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(0Pop();
- 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;
diff --git a/parser/htmlparser/src/nsDTDUtils.h b/parser/htmlparser/src/nsDTDUtils.h
index 00b11327c10..781c7c741f0 100644
--- a/parser/htmlparser/src/nsDTDUtils.h
+++ b/parser/htmlparser/src/nsDTDUtils.h
@@ -158,6 +158,7 @@ public:
protected:
nsDeque* mTokenCache[eToken_last-1];
+ nsString mEmpty;
#ifdef NS_DEBUG
int mTotals[eToken_last-1];
#endif
diff --git a/parser/htmlparser/src/nsHTMLEntities.cpp b/parser/htmlparser/src/nsHTMLEntities.cpp
index 08ebc007245..d25688b6b7b 100644
--- a/parser/htmlparser/src/nsHTMLEntities.cpp
+++ b/parser/htmlparser/src/nsHTMLEntities.cpp
@@ -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;
}
diff --git a/parser/htmlparser/src/nsHTMLTags.cpp b/parser/htmlparser/src/nsHTMLTags.cpp
index e56f16a221c..008e8d3b2fa 100644
--- a/parser/htmlparser/src/nsHTMLTags.cpp
+++ b/parser/htmlparser/src/nsHTMLTags.cpp
@@ -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;
}
}
diff --git a/parser/htmlparser/src/nsHTMLTokenizer.cpp b/parser/htmlparser/src/nsHTMLTokenizer.cpp
index b47df13c88b..297c818faf5 100644
--- a/parser/htmlparser/src/nsHTMLTokenizer.cpp
+++ b/parser/htmlparser/src/nsHTMLTokenizer.cpp
@@ -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;
}
diff --git a/parser/htmlparser/src/nsHTMLTokens.cpp b/parser/htmlparser/src/nsHTMLTokens.cpp
index 2d1cf1b1571..c517d15d43f 100644
--- a/parser/htmlparser/src/nsHTMLTokens.cpp
+++ b/parser/htmlparser/src/nsHTMLTokens.cpp
@@ -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) {
diff --git a/parser/htmlparser/src/nsParserNode.cpp b/parser/htmlparser/src/nsParserNode.cpp
index 213fa5e7a73..a30cabc31d8 100644
--- a/parser/htmlparser/src/nsParserNode.cpp
+++ b/parser/htmlparser/src/nsParserNode.cpp
@@ -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;
}
/**
diff --git a/parser/htmlparser/src/nsScanner.cpp b/parser/htmlparser/src/nsScanner.cpp
index 69310a70eb6..46615455cc0 100644
--- a/parser/htmlparser/src/nsScanner.cpp
+++ b/parser/htmlparser/src/nsScanner.cpp
@@ -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 in 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 in 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