reset pushback buffer when creating a new scanner

factored scanner creation code
This commit is contained in:
peterl%netscape.com 1999-09-22 01:19:29 +00:00
Родитель dfcf0208d4
Коммит 341ec82a84
3 изменённых файлов: 144 добавлений и 102 удалений

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

@ -144,6 +144,9 @@ public:
PRInt32* aHint); PRInt32* aHint);
protected: protected:
nsresult InitScanner(nsIUnicharInputStream* aInput, nsIURI* aURI);
nsresult ReleaseScanner(void);
PRBool GetToken(PRInt32& aErrorCode, PRBool aSkipWS); PRBool GetToken(PRInt32& aErrorCode, PRBool aSkipWS);
PRBool GetURLToken(PRInt32& aErrorCode, PRBool aSkipWS); PRBool GetURLToken(PRInt32& aErrorCode, PRBool aSkipWS);
void UngetToken(); void UngetToken();
@ -378,6 +381,36 @@ CSSParserImpl::SetChildLoader(nsICSSLoader* aChildLoader)
return NS_OK; return NS_OK;
} }
nsresult
CSSParserImpl::InitScanner(nsIUnicharInputStream* aInput, nsIURI* aURI)
{
NS_ASSERTION(! mScanner, "already have scanner");
mScanner = new nsCSSScanner();
if (! mScanner) {
return NS_ERROR_OUT_OF_MEMORY;
}
mScanner->Init(aInput);
NS_IF_RELEASE(mURL);
mURL = aURI;
NS_IF_ADDREF(mURL);
mHavePushBack = PR_FALSE;
return NS_OK;
}
nsresult
CSSParserImpl::ReleaseScanner(void)
{
if (mScanner) {
delete mScanner;
mScanner = nsnull;
}
NS_IF_RELEASE(mURL);
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
CSSParserImpl::Parse(nsIUnicharInputStream* aInput, CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
@ -395,13 +428,11 @@ CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
} }
PRInt32 errorCode = NS_OK; PRInt32 errorCode = NS_OK;
mScanner = new nsCSSScanner();
if (nsnull == mScanner) { nsresult result = InitScanner(aInput, aInputURL);
return NS_ERROR_OUT_OF_MEMORY; if (! NS_SUCCEEDED(result)) {
return result;
} }
mScanner->Init(aInput);
mURL = aInputURL;
NS_IF_ADDREF(aInputURL);
PRInt32 ruleCount = 0; PRInt32 ruleCount = 0;
mSheet->StyleRuleCount(ruleCount); mSheet->StyleRuleCount(ruleCount);
@ -448,9 +479,7 @@ CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
mSection = eCSSSection_General; mSection = eCSSSection_General;
} }
} }
delete mScanner; ReleaseScanner();
mScanner = nsnull;
NS_IF_RELEASE(mURL);
aResult = mSheet; aResult = mSheet;
NS_ADDREF(aResult); NS_ADDREF(aResult);
@ -476,16 +505,11 @@ CSSParserImpl::ParseDeclarations(const nsString& aDeclaration,
return rv; return rv;
} }
mScanner = new nsCSSScanner(); rv = InitScanner(input, aBaseURL);
if (nsnull == mScanner) {
NS_RELEASE(input);
return NS_ERROR_OUT_OF_MEMORY;
}
mScanner->Init(input);
NS_RELEASE(input); NS_RELEASE(input);
if (! NS_SUCCEEDED(rv)) {
mURL = aBaseURL; return rv;
NS_IF_ADDREF(mURL); }
mSection = eCSSSection_General; mSection = eCSSSection_General;
PRInt32 errorCode = NS_OK; PRInt32 errorCode = NS_OK;
@ -503,9 +527,7 @@ CSSParserImpl::ParseDeclarations(const nsString& aDeclaration,
aResult = nsnull; aResult = nsnull;
} }
delete mScanner; ReleaseScanner();
mScanner = nsnull;
NS_IF_RELEASE(mURL);
return NS_OK; return NS_OK;
} }
@ -529,16 +551,11 @@ CSSParserImpl::ParseAndAppendDeclaration(const nsString& aBuffer,
return rv; return rv;
} }
mScanner = new nsCSSScanner(); rv = InitScanner(input, aBaseURL);
if (nsnull == mScanner) {
NS_RELEASE(input);
return NS_ERROR_OUT_OF_MEMORY;
}
mScanner->Init(input);
NS_RELEASE(input); NS_RELEASE(input);
if (! NS_SUCCEEDED(rv)) {
mURL = aBaseURL; return rv;
NS_IF_ADDREF(mURL); }
mSection = eCSSSection_General; mSection = eCSSSection_General;
PRInt32 errorCode = NS_OK; PRInt32 errorCode = NS_OK;
@ -552,10 +569,7 @@ CSSParserImpl::ParseAndAppendDeclaration(const nsString& aBuffer,
*aHint = hint; *aHint = hint;
} }
delete mScanner; ReleaseScanner();
mScanner = nsnull;
NS_IF_RELEASE(mURL);
return NS_OK; return NS_OK;
} }

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

@ -144,6 +144,9 @@ public:
PRInt32* aHint); PRInt32* aHint);
protected: protected:
nsresult InitScanner(nsIUnicharInputStream* aInput, nsIURI* aURI);
nsresult ReleaseScanner(void);
PRBool GetToken(PRInt32& aErrorCode, PRBool aSkipWS); PRBool GetToken(PRInt32& aErrorCode, PRBool aSkipWS);
PRBool GetURLToken(PRInt32& aErrorCode, PRBool aSkipWS); PRBool GetURLToken(PRInt32& aErrorCode, PRBool aSkipWS);
void UngetToken(); void UngetToken();
@ -378,6 +381,36 @@ CSSParserImpl::SetChildLoader(nsICSSLoader* aChildLoader)
return NS_OK; return NS_OK;
} }
nsresult
CSSParserImpl::InitScanner(nsIUnicharInputStream* aInput, nsIURI* aURI)
{
NS_ASSERTION(! mScanner, "already have scanner");
mScanner = new nsCSSScanner();
if (! mScanner) {
return NS_ERROR_OUT_OF_MEMORY;
}
mScanner->Init(aInput);
NS_IF_RELEASE(mURL);
mURL = aURI;
NS_IF_ADDREF(mURL);
mHavePushBack = PR_FALSE;
return NS_OK;
}
nsresult
CSSParserImpl::ReleaseScanner(void)
{
if (mScanner) {
delete mScanner;
mScanner = nsnull;
}
NS_IF_RELEASE(mURL);
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
CSSParserImpl::Parse(nsIUnicharInputStream* aInput, CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
@ -395,13 +428,11 @@ CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
} }
PRInt32 errorCode = NS_OK; PRInt32 errorCode = NS_OK;
mScanner = new nsCSSScanner();
if (nsnull == mScanner) { nsresult result = InitScanner(aInput, aInputURL);
return NS_ERROR_OUT_OF_MEMORY; if (! NS_SUCCEEDED(result)) {
return result;
} }
mScanner->Init(aInput);
mURL = aInputURL;
NS_IF_ADDREF(aInputURL);
PRInt32 ruleCount = 0; PRInt32 ruleCount = 0;
mSheet->StyleRuleCount(ruleCount); mSheet->StyleRuleCount(ruleCount);
@ -448,9 +479,7 @@ CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
mSection = eCSSSection_General; mSection = eCSSSection_General;
} }
} }
delete mScanner; ReleaseScanner();
mScanner = nsnull;
NS_IF_RELEASE(mURL);
aResult = mSheet; aResult = mSheet;
NS_ADDREF(aResult); NS_ADDREF(aResult);
@ -476,16 +505,11 @@ CSSParserImpl::ParseDeclarations(const nsString& aDeclaration,
return rv; return rv;
} }
mScanner = new nsCSSScanner(); rv = InitScanner(input, aBaseURL);
if (nsnull == mScanner) {
NS_RELEASE(input);
return NS_ERROR_OUT_OF_MEMORY;
}
mScanner->Init(input);
NS_RELEASE(input); NS_RELEASE(input);
if (! NS_SUCCEEDED(rv)) {
mURL = aBaseURL; return rv;
NS_IF_ADDREF(mURL); }
mSection = eCSSSection_General; mSection = eCSSSection_General;
PRInt32 errorCode = NS_OK; PRInt32 errorCode = NS_OK;
@ -503,9 +527,7 @@ CSSParserImpl::ParseDeclarations(const nsString& aDeclaration,
aResult = nsnull; aResult = nsnull;
} }
delete mScanner; ReleaseScanner();
mScanner = nsnull;
NS_IF_RELEASE(mURL);
return NS_OK; return NS_OK;
} }
@ -529,16 +551,11 @@ CSSParserImpl::ParseAndAppendDeclaration(const nsString& aBuffer,
return rv; return rv;
} }
mScanner = new nsCSSScanner(); rv = InitScanner(input, aBaseURL);
if (nsnull == mScanner) {
NS_RELEASE(input);
return NS_ERROR_OUT_OF_MEMORY;
}
mScanner->Init(input);
NS_RELEASE(input); NS_RELEASE(input);
if (! NS_SUCCEEDED(rv)) {
mURL = aBaseURL; return rv;
NS_IF_ADDREF(mURL); }
mSection = eCSSSection_General; mSection = eCSSSection_General;
PRInt32 errorCode = NS_OK; PRInt32 errorCode = NS_OK;
@ -552,10 +569,7 @@ CSSParserImpl::ParseAndAppendDeclaration(const nsString& aBuffer,
*aHint = hint; *aHint = hint;
} }
delete mScanner; ReleaseScanner();
mScanner = nsnull;
NS_IF_RELEASE(mURL);
return NS_OK; return NS_OK;
} }

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

@ -144,6 +144,9 @@ public:
PRInt32* aHint); PRInt32* aHint);
protected: protected:
nsresult InitScanner(nsIUnicharInputStream* aInput, nsIURI* aURI);
nsresult ReleaseScanner(void);
PRBool GetToken(PRInt32& aErrorCode, PRBool aSkipWS); PRBool GetToken(PRInt32& aErrorCode, PRBool aSkipWS);
PRBool GetURLToken(PRInt32& aErrorCode, PRBool aSkipWS); PRBool GetURLToken(PRInt32& aErrorCode, PRBool aSkipWS);
void UngetToken(); void UngetToken();
@ -378,6 +381,36 @@ CSSParserImpl::SetChildLoader(nsICSSLoader* aChildLoader)
return NS_OK; return NS_OK;
} }
nsresult
CSSParserImpl::InitScanner(nsIUnicharInputStream* aInput, nsIURI* aURI)
{
NS_ASSERTION(! mScanner, "already have scanner");
mScanner = new nsCSSScanner();
if (! mScanner) {
return NS_ERROR_OUT_OF_MEMORY;
}
mScanner->Init(aInput);
NS_IF_RELEASE(mURL);
mURL = aURI;
NS_IF_ADDREF(mURL);
mHavePushBack = PR_FALSE;
return NS_OK;
}
nsresult
CSSParserImpl::ReleaseScanner(void)
{
if (mScanner) {
delete mScanner;
mScanner = nsnull;
}
NS_IF_RELEASE(mURL);
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
CSSParserImpl::Parse(nsIUnicharInputStream* aInput, CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
@ -395,13 +428,11 @@ CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
} }
PRInt32 errorCode = NS_OK; PRInt32 errorCode = NS_OK;
mScanner = new nsCSSScanner();
if (nsnull == mScanner) { nsresult result = InitScanner(aInput, aInputURL);
return NS_ERROR_OUT_OF_MEMORY; if (! NS_SUCCEEDED(result)) {
return result;
} }
mScanner->Init(aInput);
mURL = aInputURL;
NS_IF_ADDREF(aInputURL);
PRInt32 ruleCount = 0; PRInt32 ruleCount = 0;
mSheet->StyleRuleCount(ruleCount); mSheet->StyleRuleCount(ruleCount);
@ -448,9 +479,7 @@ CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
mSection = eCSSSection_General; mSection = eCSSSection_General;
} }
} }
delete mScanner; ReleaseScanner();
mScanner = nsnull;
NS_IF_RELEASE(mURL);
aResult = mSheet; aResult = mSheet;
NS_ADDREF(aResult); NS_ADDREF(aResult);
@ -476,16 +505,11 @@ CSSParserImpl::ParseDeclarations(const nsString& aDeclaration,
return rv; return rv;
} }
mScanner = new nsCSSScanner(); rv = InitScanner(input, aBaseURL);
if (nsnull == mScanner) {
NS_RELEASE(input);
return NS_ERROR_OUT_OF_MEMORY;
}
mScanner->Init(input);
NS_RELEASE(input); NS_RELEASE(input);
if (! NS_SUCCEEDED(rv)) {
mURL = aBaseURL; return rv;
NS_IF_ADDREF(mURL); }
mSection = eCSSSection_General; mSection = eCSSSection_General;
PRInt32 errorCode = NS_OK; PRInt32 errorCode = NS_OK;
@ -503,9 +527,7 @@ CSSParserImpl::ParseDeclarations(const nsString& aDeclaration,
aResult = nsnull; aResult = nsnull;
} }
delete mScanner; ReleaseScanner();
mScanner = nsnull;
NS_IF_RELEASE(mURL);
return NS_OK; return NS_OK;
} }
@ -529,16 +551,11 @@ CSSParserImpl::ParseAndAppendDeclaration(const nsString& aBuffer,
return rv; return rv;
} }
mScanner = new nsCSSScanner(); rv = InitScanner(input, aBaseURL);
if (nsnull == mScanner) {
NS_RELEASE(input);
return NS_ERROR_OUT_OF_MEMORY;
}
mScanner->Init(input);
NS_RELEASE(input); NS_RELEASE(input);
if (! NS_SUCCEEDED(rv)) {
mURL = aBaseURL; return rv;
NS_IF_ADDREF(mURL); }
mSection = eCSSSection_General; mSection = eCSSSection_General;
PRInt32 errorCode = NS_OK; PRInt32 errorCode = NS_OK;
@ -552,10 +569,7 @@ CSSParserImpl::ParseAndAppendDeclaration(const nsString& aBuffer,
*aHint = hint; *aHint = hint;
} }
delete mScanner; ReleaseScanner();
mScanner = nsnull;
NS_IF_RELEASE(mURL);
return NS_OK; return NS_OK;
} }