fixed bug 9386 and added Terminate() to parser API

This commit is contained in:
rickg%netscape.com 1999-07-08 04:39:38 +00:00
Родитель ecedd77f78
Коммит 7d4586a4d1
10 изменённых файлов: 64 добавлений и 48 удалений

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

@ -462,9 +462,9 @@ nsresult nsHTMLTokenizer::ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScan
if((eHTMLTag_style==theTag) || (eHTMLTag_script==theTag)) {
nsAutoString endTag(NS_EnumToTag(theTag));
endTag.Insert("</",0,2);
endTag.Append(">");
CToken* textToken=theRecycler->CreateTokenOfType(eToken_text,theTag,endTag);
result=((CTextToken*)textToken)->ConsumeUntil(0,PRBool(eHTMLTag_style==theTag),aScanner,endTag); //tell new token to finish consuming text...
//endTag.Append(">");
CToken* endToken=theRecycler->CreateTokenOfType(eToken_end,theTag,endTag);
AddToken(textToken,result,mTokenDeque,theRecycler);
AddToken(endToken,result,mTokenDeque,theRecycler);

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

@ -507,11 +507,12 @@ nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
* @return error result
*/
nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScanner& aScanner,nsString& aTerminalString){
PRBool done=PR_FALSE;
nsresult result=NS_OK;
nsString temp;
PRUnichar theChar;
nsAutoString theRight;
PRBool done=PR_FALSE;
nsresult result=NS_OK;
nsString temp;
PRUnichar theChar;
nsAutoString theRight;
PRInt32 rpos=0;
//We're going to try a new algorithm here. Rather than scan for the matching
//end tag like we used to do, we're now going to scan for whitespace and comments.
@ -519,7 +520,7 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
//target endtag, or the start of another comment.
static nsAutoString theWhitespace2("\b\t ");
PRInt32 termStrLen=aTerminalString.Length();
while((!done) && (NS_OK==result)) {
result=aScanner.GetChar(aChar);
if((NS_OK==result) && (kLessThan==aChar)) {
@ -553,17 +554,20 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
temp+=aChar;
result=aScanner.ReadUntil(temp,kLessThan,PR_FALSE);
}
temp.Right(theRight,aTerminalString.Length());
done=PRBool(0==theRight.Compare(aTerminalString,PR_TRUE));
temp.Right(theRight,termStrLen+10); //first, get a wad of chars from the temp string
rpos=theRight.RFind('<'); //now scan for the '<'
if(-1<rpos)
rpos=theRight.RFind(aTerminalString,PR_TRUE,rpos);
done=PRBool(-1<rpos);
} //while
int len=temp.Length();
temp.Truncate(len-aTerminalString.Length());
temp.Truncate(len-(theRight.Length()-rpos));
mTextValue=temp;
// Make aTerminalString contain the name of the end tag ** as seen in **
// the document and not the made up one.
theRight.Cut(0,2);
theRight.Cut((theRight.Length()-1),1);
theRight.Cut(0,rpos+2);
theRight.Truncate(theRight.Length()-1);
aTerminalString = theRight;
return result;
}
@ -854,17 +858,6 @@ nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString)
nsresult CCommentToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
PRBool theStrictForm=PR_FALSE;
nsresult result=(theStrictForm) ? ConsumeStrictComment(aChar,aScanner,mTextValue) : ConsumeComment(aChar,aScanner,mTextValue);
/*
//this change is here to make the editor teams' life easier.
//I'm removing the leading and trailing markup...
if(0==mTextValue.Find("<!"))
mTextValue.Cut(0,2); //trim off 1st 2 chars...
if(kGreaterThan==mTextValue.Last())
mTextValue.Truncate(mTextValue.Length()-1); //trim off last char
*/
return result;
}

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

@ -170,6 +170,7 @@ class nsIParser : public nsISupports {
virtual nsresult Parse(nsIURI* aURL,nsIStreamObserver* aListener = nsnull,PRBool aEnableVerify=PR_FALSE, void* aKey=0) = 0;
virtual nsresult Parse(nsIInputStream& aStream, PRBool aEnableVerify=PR_FALSE, void* aKey=0) = 0;
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall) = 0;
virtual nsresult Terminate(void) = 0;
virtual PRBool IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType)=0;
virtual nsresult ParseFragment(const nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType)=0;

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

@ -575,6 +575,19 @@ void nsParser::SetUnusedInput(nsString& aBuffer) {
mUnusedInput=aBuffer;
}
/**
* Call this when you want to *force* the parser to terminate the
* parsing process altogether. This is binary -- so once you terminate
* you can't resume without restarting altogether.
*
* @update gess 7/4/99
* @return should return NS_OK once implemented
*/
nsresult nsParser::Terminate(void){
NS_NOTYETIMPLEMENTED("Call again later");
nsresult result=NS_ERROR_NOT_IMPLEMENTED;
return result;
}
/**
* Call this when you want control whether or not the parser will parse

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

@ -204,7 +204,8 @@ friend class CTokenHandler;
* @param aState determines whether we parse/tokenize or just cache.
* @return current state
*/
virtual PRBool EnableParser(PRBool aState);
virtual PRBool EnableParser(PRBool aState);
virtual nsresult Terminate(void);
/**
* Call this to query whether the parser is enabled or not.

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

@ -462,9 +462,9 @@ nsresult nsHTMLTokenizer::ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScan
if((eHTMLTag_style==theTag) || (eHTMLTag_script==theTag)) {
nsAutoString endTag(NS_EnumToTag(theTag));
endTag.Insert("</",0,2);
endTag.Append(">");
CToken* textToken=theRecycler->CreateTokenOfType(eToken_text,theTag,endTag);
result=((CTextToken*)textToken)->ConsumeUntil(0,PRBool(eHTMLTag_style==theTag),aScanner,endTag); //tell new token to finish consuming text...
//endTag.Append(">");
CToken* endToken=theRecycler->CreateTokenOfType(eToken_end,theTag,endTag);
AddToken(textToken,result,mTokenDeque,theRecycler);
AddToken(endToken,result,mTokenDeque,theRecycler);

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

@ -507,11 +507,12 @@ nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
* @return error result
*/
nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScanner& aScanner,nsString& aTerminalString){
PRBool done=PR_FALSE;
nsresult result=NS_OK;
nsString temp;
PRUnichar theChar;
nsAutoString theRight;
PRBool done=PR_FALSE;
nsresult result=NS_OK;
nsString temp;
PRUnichar theChar;
nsAutoString theRight;
PRInt32 rpos=0;
//We're going to try a new algorithm here. Rather than scan for the matching
//end tag like we used to do, we're now going to scan for whitespace and comments.
@ -519,7 +520,7 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
//target endtag, or the start of another comment.
static nsAutoString theWhitespace2("\b\t ");
PRInt32 termStrLen=aTerminalString.Length();
while((!done) && (NS_OK==result)) {
result=aScanner.GetChar(aChar);
if((NS_OK==result) && (kLessThan==aChar)) {
@ -553,17 +554,20 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
temp+=aChar;
result=aScanner.ReadUntil(temp,kLessThan,PR_FALSE);
}
temp.Right(theRight,aTerminalString.Length());
done=PRBool(0==theRight.Compare(aTerminalString,PR_TRUE));
temp.Right(theRight,termStrLen+10); //first, get a wad of chars from the temp string
rpos=theRight.RFind('<'); //now scan for the '<'
if(-1<rpos)
rpos=theRight.RFind(aTerminalString,PR_TRUE,rpos);
done=PRBool(-1<rpos);
} //while
int len=temp.Length();
temp.Truncate(len-aTerminalString.Length());
temp.Truncate(len-(theRight.Length()-rpos));
mTextValue=temp;
// Make aTerminalString contain the name of the end tag ** as seen in **
// the document and not the made up one.
theRight.Cut(0,2);
theRight.Cut((theRight.Length()-1),1);
theRight.Cut(0,rpos+2);
theRight.Truncate(theRight.Length()-1);
aTerminalString = theRight;
return result;
}
@ -854,17 +858,6 @@ nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString)
nsresult CCommentToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
PRBool theStrictForm=PR_FALSE;
nsresult result=(theStrictForm) ? ConsumeStrictComment(aChar,aScanner,mTextValue) : ConsumeComment(aChar,aScanner,mTextValue);
/*
//this change is here to make the editor teams' life easier.
//I'm removing the leading and trailing markup...
if(0==mTextValue.Find("<!"))
mTextValue.Cut(0,2); //trim off 1st 2 chars...
if(kGreaterThan==mTextValue.Last())
mTextValue.Truncate(mTextValue.Length()-1); //trim off last char
*/
return result;
}

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

@ -170,6 +170,7 @@ class nsIParser : public nsISupports {
virtual nsresult Parse(nsIURI* aURL,nsIStreamObserver* aListener = nsnull,PRBool aEnableVerify=PR_FALSE, void* aKey=0) = 0;
virtual nsresult Parse(nsIInputStream& aStream, PRBool aEnableVerify=PR_FALSE, void* aKey=0) = 0;
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall) = 0;
virtual nsresult Terminate(void) = 0;
virtual PRBool IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType)=0;
virtual nsresult ParseFragment(const nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType)=0;

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

@ -575,6 +575,19 @@ void nsParser::SetUnusedInput(nsString& aBuffer) {
mUnusedInput=aBuffer;
}
/**
* Call this when you want to *force* the parser to terminate the
* parsing process altogether. This is binary -- so once you terminate
* you can't resume without restarting altogether.
*
* @update gess 7/4/99
* @return should return NS_OK once implemented
*/
nsresult nsParser::Terminate(void){
NS_NOTYETIMPLEMENTED("Call again later");
nsresult result=NS_ERROR_NOT_IMPLEMENTED;
return result;
}
/**
* Call this when you want control whether or not the parser will parse

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

@ -204,7 +204,8 @@ friend class CTokenHandler;
* @param aState determines whether we parse/tokenize or just cache.
* @return current state
*/
virtual PRBool EnableParser(PRBool aState);
virtual PRBool EnableParser(PRBool aState);
virtual nsresult Terminate(void);
/**
* Call this to query whether the parser is enabled or not.