diff --git a/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp b/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp
index 3d0872fb0a7..7f43a0b638b 100644
--- a/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp
+++ b/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp
@@ -37,9 +37,9 @@
*
* ***** END LICENSE BLOCK ***** */
-#include
+#include
#include
-#include
+#include
#include "nsScanner.h"
#include "nsToken.h"
#include "nsIAtom.h"
@@ -58,10 +58,10 @@ static const PRUnichar sUserdefined[] = {'u', 's', 'e', 'r', 'd', 'e', 'f',
'i', 'n', 'e', 'd', 0};
static const PRUnichar kAttributeTerminalChars[] = {
- PRUnichar('&'), PRUnichar('\b'), PRUnichar('\t'),
- PRUnichar('\n'), PRUnichar('\r'), PRUnichar(' '),
- PRUnichar('>'),
- PRUnichar(0)
+ PRUnichar('&'), PRUnichar('\b'), PRUnichar('\t'),
+ PRUnichar('\n'), PRUnichar('\r'), PRUnichar(' '),
+ PRUnichar('>'),
+ PRUnichar(0)
};
static void AppendNCR(nsSubstring& aString, PRInt32 aNCRValue);
@@ -75,67 +75,63 @@ static void AppendNCR(nsSubstring& aString, PRInt32 aNCRValue);
* @param aFlag If NS_IPARSER_FLAG_VIEW_SOURCE do not reduce entities...
* @return error result
*/
-static
-nsresult ConsumeEntity(nsScannerSharedSubstring& aString,
- nsScanner& aScanner,
- PRBool aIECompatible,
- PRInt32 aFlag)
+static nsresult
+ConsumeEntity(nsScannerSharedSubstring& aString,
+ nsScanner& aScanner,
+ PRBool aIECompatible,
+ PRInt32 aFlag)
{
- nsresult result=NS_OK;
+ nsresult result = NS_OK;
PRUnichar ch;
- result=aScanner.Peek(ch, 1);
+ result = aScanner.Peek(ch, 1);
if (NS_SUCCEEDED(result)) {
- PRUnichar amp=0;
- PRInt32 theNCRValue=0;
+ PRUnichar amp = 0;
+ PRInt32 theNCRValue = 0;
nsAutoString entity;
if (nsCRT::IsAsciiAlpha(ch) && !(aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
- result=CEntityToken::ConsumeEntity(ch,entity,aScanner);
+ result = CEntityToken::ConsumeEntity(ch, entity, aScanner);
if (NS_SUCCEEDED(result)) {
theNCRValue = nsHTMLEntities::EntityToUnicode(entity);
- PRUnichar theTermChar=entity.Last();
+ PRUnichar theTermChar = entity.Last();
// If an entity value is greater than 255 then:
// Nav 4.x does not treat it as an entity,
// IE treats it as an entity if terminated with a semicolon.
// Resembling IE!!
nsSubstring &writable = aString.writable();
- if(theNCRValue < 0 ||
- (aIECompatible && theNCRValue > 255 && theTermChar != ';')) {
+ if (theNCRValue < 0 ||
+ (aIECompatible && theNCRValue > 255 && theTermChar != ';')) {
// Looks like we're not dealing with an entity
writable.Append(kAmpersand);
writable.Append(entity);
- }
- else {
+ } else {
// A valid entity so reduce it.
writable.Append(PRUnichar(theNCRValue));
}
}
- }
- else if (ch==kHashsign && !(aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
- result=CEntityToken::ConsumeEntity(ch,entity,aScanner);
+ } else if (ch == kHashsign && !(aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
+ result = CEntityToken::ConsumeEntity(ch, entity, aScanner);
if (NS_SUCCEEDED(result)) {
nsSubstring &writable = aString.writable();
if (result == NS_HTMLTOKENS_NOT_AN_ENTITY) {
// Looked like an entity but it's not
aScanner.GetChar(amp);
writable.Append(amp);
- result = NS_OK; // just being safe..
- }
- else {
+ result = NS_OK;
+ } else {
PRInt32 err;
- theNCRValue=entity.ToInteger(&err,kAutoDetect);
+ theNCRValue = entity.ToInteger(&err, kAutoDetect);
AppendNCR(writable, theNCRValue);
}
}
- }
- else {
+ } else {
// What we thought as entity is not really an entity...
aScanner.GetChar(amp);
aString.writable().Append(amp);
- }//if
+ }
}
return result;
@@ -143,7 +139,7 @@ nsresult ConsumeEntity(nsScannerSharedSubstring& aString,
/*
* This general purpose method is used when you want to
- * consume attributed text value.
+ * consume attributed text value.
* Note: It also reduces entities.
*
* @param aNewlineCount -- the newline count to increment when hitting newlines
@@ -159,47 +155,43 @@ nsresult ConsumeEntity(nsScannerSharedSubstring& aString,
* @param aFlag - contains information such as |dtd mode|view mode|doctype|etc...
* @return error result
*/
-static
-nsresult ConsumeUntil(nsScannerSharedSubstring& aString,
- PRInt32& aNewlineCount,
- nsScanner& aScanner,
- const nsReadEndCondition& aEndCondition,
- PRBool aAllowNewlines,
- PRBool aIECompatEntities,
- PRInt32 aFlag)
+static nsresult
+ConsumeUntil(nsScannerSharedSubstring& aString,
+ PRInt32& aNewlineCount,
+ nsScanner& aScanner,
+ const nsReadEndCondition& aEndCondition,
+ PRBool aAllowNewlines,
+ PRBool aIECompatEntities,
+ PRInt32 aFlag)
{
nsresult result = NS_OK;
PRBool done = PR_FALSE;
-
+
do {
- result = aScanner.ReadUntil(aString,aEndCondition,PR_FALSE);
- if(NS_SUCCEEDED(result)) {
+ result = aScanner.ReadUntil(aString, aEndCondition, PR_FALSE);
+ if (NS_SUCCEEDED(result)) {
PRUnichar ch;
aScanner.Peek(ch);
- if(ch == kAmpersand) {
+ if (ch == kAmpersand) {
result = ConsumeEntity(aString, aScanner, aIECompatEntities, aFlag);
- }
- else if(ch == kCR && aAllowNewlines) {
+ } else if (ch == kCR && aAllowNewlines) {
aScanner.GetChar(ch);
result = aScanner.Peek(ch);
if (NS_SUCCEEDED(result)) {
nsSubstring &writable = aString.writable();
- if(ch == kNewLine) {
+ if (ch == kNewLine) {
writable.AppendLiteral("\r\n");
aScanner.GetChar(ch);
- }
- else {
+ } else {
writable.Append(PRUnichar('\r'));
}
++aNewlineCount;
}
- }
- else if(ch == kNewLine && aAllowNewlines) {
+ } else if (ch == kNewLine && aAllowNewlines) {
aScanner.GetChar(ch);
aString.writable().Append(PRUnichar('\n'));
++aNewlineCount;
- }
- else {
+ } else {
done = PR_TRUE;
}
}
@@ -212,48 +204,48 @@ nsresult ConsumeUntil(nsScannerSharedSubstring& aString,
And now for the token classes...
**************************************************************/
-/*
- * constructor from tag id
- *
- * @update gess 3/25/98
- * @param
- * @return
+/**
+ * Constructor from tag id
*/
-CHTMLToken::CHTMLToken(eHTMLTags aTag) : CToken(aTag) {
+CHTMLToken::CHTMLToken(eHTMLTags aTag)
+ : CToken(aTag)
+{
}
-CHTMLToken::~CHTMLToken() {
-
+CHTMLToken::~CHTMLToken()
+{
}
/*
- * constructor from tag id
- *
- * @update gess 3/25/98
- * @param
- * @return
+ * Constructor from tag id
*/
-CStartToken::CStartToken(eHTMLTags aTag) : CHTMLToken(aTag) {
- mEmpty=PR_FALSE;
- mContainerInfo=eFormUnknown;
+CStartToken::CStartToken(eHTMLTags aTag)
+ : CHTMLToken(aTag)
+{
+ mEmpty = PR_FALSE;
+ mContainerInfo = eFormUnknown;
#ifdef DEBUG
mAttributed = PR_FALSE;
#endif
}
-CStartToken::CStartToken(const nsAString& aName) : CHTMLToken(eHTMLTag_unknown) {
- mEmpty=PR_FALSE;
- mContainerInfo=eFormUnknown;
+CStartToken::CStartToken(const nsAString& aName)
+ : CHTMLToken(eHTMLTag_unknown)
+{
+ mEmpty = PR_FALSE;
+ mContainerInfo = eFormUnknown;
mTextValue.Assign(aName);
#ifdef DEBUG
mAttributed = PR_FALSE;
#endif
}
-CStartToken::CStartToken(const nsAString& aName,eHTMLTags aTag) : CHTMLToken(aTag) {
- mEmpty=PR_FALSE;
- mContainerInfo=eFormUnknown;
+CStartToken::CStartToken(const nsAString& aName, eHTMLTags aTag)
+ : CHTMLToken(aTag)
+{
+ mEmpty = PR_FALSE;
+ mContainerInfo = eFormUnknown;
mTextValue.Assign(aName);
#ifdef DEBUG
mAttributed = PR_FALSE;
@@ -261,70 +253,47 @@ CStartToken::CStartToken(const nsAString& aName,eHTMLTags aTag) : CHTMLToken(aTa
}
/*
- * This method returns the typeid (the tag type) for this token.
- *
- * @update gess 3/25/98
- * @param
- * @return
+ * This method returns the typeid (the tag type) for this token.
*/
-PRInt32 CStartToken::GetTypeID(){
- if(eHTMLTag_unknown==mTypeID) {
+PRInt32
+CStartToken::GetTypeID()
+{
+ if (eHTMLTag_unknown == mTypeID) {
mTypeID = nsHTMLTags::LookupTag(mTextValue);
}
return mTypeID;
}
-/*
- *
- *
- * @update gess 3/25/98
- * @param
- * @return
- */
-PRInt32 CStartToken::GetTokenType(void) {
+PRInt32
+CStartToken::GetTokenType()
+{
return eToken_start;
}
-/*
- *
- *
- * @update gess 3/25/98
- * @param
- * @return
- */
-void CStartToken::SetEmpty(PRBool aValue) {
- mEmpty=aValue;
+void
+CStartToken::SetEmpty(PRBool aValue)
+{
+ mEmpty = aValue;
}
-/*
- *
- *
- * @update gess 3/25/98
- * @param
- * @return
- */
-PRBool CStartToken::IsEmpty(void) {
+PRBool
+CStartToken::IsEmpty()
+{
return mEmpty;
}
-
/*
- * Consume the identifier portion of the start tag
- *
- * @update gess 3/25/98
- * @param aChar -- last char consumed from stream
- * @param aScanner -- controller of underlying input source
- * @param aFlag - contains information such as |dtd mode|view mode|doctype|etc...
- * @return error result
+ * Consume the identifier portion of the start tag
*/
-nsresult CStartToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag) {
+nsresult
+CStartToken::Consume(PRUnichar aChar, nsScanner& aScanner, PRInt32 aFlag)
+{
+ // If you're here, we've already Consumed the < char, and are
+ // ready to Consume the rest of the open tag identifier.
+ // Stop consuming as soon as you see a space or a '>'.
+ // NOTE: We don't Consume the tag attributes here, nor do we eat the ">"
- //if you're here, we've already Consumed the < char, and are
- //ready to Consume the rest of the open tag identifier.
- //Stop consuming as soon as you see a space or a '>'.
- //NOTE: We don't Consume the tag attributes here, nor do we eat the ">"
-
- nsresult result=NS_OK;
+ nsresult result = NS_OK;
nsScannerSharedSubstring tagIdent;
if (aFlag & NS_IPARSER_FLAG_HTML) {
@@ -332,11 +301,11 @@ nsresult CStartToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag
mTypeID = (PRInt32)nsHTMLTags::LookupTag(tagIdent.str());
// Save the original tag string if this is user-defined or if we
// are viewing source
- if(eHTMLTag_userdefined==mTypeID || (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
+ if (eHTMLTag_userdefined == mTypeID ||
+ (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
mTextValue = tagIdent.str();
}
- }
- else {
+ } else {
result = aScanner.ReadTagIdentifier(tagIdent);
mTextValue = tagIdent.str();
mTypeID = nsHTMLTags::LookupTag(mTextValue);
@@ -354,93 +323,74 @@ nsresult CStartToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag
return result;
}
-
-const nsSubstring& CStartToken::GetStringValue()
+const nsSubstring&
+CStartToken::GetStringValue()
{
- if((eHTMLTag_unknown'));
}
-/*
- * constructor from tag id
- *
- * @update gess 3/25/98
- * @param
- * @return
- */
-CEndToken::CEndToken(eHTMLTags aTag) : CHTMLToken(aTag) {
+CEndToken::CEndToken(eHTMLTags aTag)
+ : CHTMLToken(aTag)
+{
}
-CEndToken::CEndToken(const nsAString& aName) : CHTMLToken(eHTMLTag_unknown) {
+CEndToken::CEndToken(const nsAString& aName)
+ : CHTMLToken(eHTMLTag_unknown)
+{
mTextValue.Assign(aName);
}
-CEndToken::CEndToken(const nsAString& aName,eHTMLTags aTag) : CHTMLToken(aTag) {
+CEndToken::CEndToken(const nsAString& aName, eHTMLTags aTag)
+ : CHTMLToken(aTag)
+{
mTextValue.Assign(aName);
}
-/*
- * Consume the identifier portion of the end tag
- *
- * @update gess 3/25/98
- * @param aChar -- last char consumed from stream
- * @param aScanner -- controller of underlying input source
- * @param aFlag - contains information such as |dtd mode|view mode|doctype|etc...
- * @return error result
- */
-nsresult CEndToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag)
+nsresult
+CEndToken::Consume(PRUnichar aChar, nsScanner& aScanner, PRInt32 aFlag)
{
nsresult result = NS_OK;
nsScannerSharedSubstring tagIdent;
if (aFlag & NS_IPARSER_FLAG_HTML) {
result = aScanner.ReadTagIdentifier(tagIdent);
-
+
mTypeID = (PRInt32)nsHTMLTags::LookupTag(tagIdent.str());
// Save the original tag string if this is user-defined or if we
// are viewing source
- if(eHTMLTag_userdefined==mTypeID ||
- (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
+ if (eHTMLTag_userdefined == mTypeID ||
+ (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
mTextValue = tagIdent.str();
}
- }
- else {
+ } else {
result = aScanner.ReadTagIdentifier(tagIdent);
mTextValue = tagIdent.str();
mTypeID = nsHTMLTags::LookupTag(mTextValue);
@@ -463,130 +413,97 @@ nsresult CEndToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag)
* Asks the token to determine the HTMLTag type of
* the token. This turns around and looks up the tag name
* in the tag dictionary.
- *
- * @update gess 3/25/98
- * @param
- * @return eHTMLTag id of this endtag
*/
-PRInt32 CEndToken::GetTypeID(){
- if(eHTMLTag_unknown==mTypeID) {
+PRInt32
+CEndToken::GetTypeID()
+{
+ if (eHTMLTag_unknown == mTypeID) {
mTypeID = nsHTMLTags::LookupTag(mTextValue);
- switch(mTypeID) {
+ switch (mTypeID) {
case eHTMLTag_dir:
case eHTMLTag_menu:
- mTypeID=eHTMLTag_ul;
+ mTypeID = eHTMLTag_ul;
break;
+
default:
break;
}
}
+
return mTypeID;
}
-/*
- *
- *
- * @update gess 3/25/98
- * @param
- * @return
- */
-PRInt32 CEndToken::GetTokenType(void) {
+PRInt32
+CEndToken::GetTokenType()
+{
return eToken_end;
}
-const nsSubstring& CEndToken::GetStringValue()
+const nsSubstring&
+CEndToken::GetStringValue()
{
- if((eHTMLTag_unknown'));
}
-/*
- * default constructor
- *
- * @update gess 3/25/98
- * @param aName -- string to init token name with
- * @return
- */
-CTextToken::CTextToken() : CHTMLToken(eHTMLTag_text) {
+CTextToken::CTextToken()
+ : CHTMLToken(eHTMLTag_text)
+{
}
-
-/*
- * string based constructor
- *
- * @update gess 3/25/98
- * @param aName -- string to init token name with
- * @return
- */
-CTextToken::CTextToken(const nsAString& aName) : CHTMLToken(eHTMLTag_text) {
+CTextToken::CTextToken(const nsAString& aName)
+ : CHTMLToken(eHTMLTag_text)
+{
mTextValue.Rebind(aName);
}
-/*
- *
- *
- * @update gess 3/25/98
- * @param
- * @return
- */
-PRInt32 CTextToken::GetTokenType(void) {
+PRInt32
+CTextToken::GetTokenType()
+{
return eToken_text;
}
-PRInt32 CTextToken::GetTextLength(void) {
+PRInt32
+CTextToken::GetTextLength()
+{
return mTextValue.Length();
}
-/*
- * Consume as much clear text from scanner as possible.
- *
- * @update gess 3/25/98
- * @param aChar -- last char consumed from stream
- * @param aScanner -- controller of underlying input source
- * @return error result
- */
-nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag) {
- static const PRUnichar theTerminalsChars[] =
+nsresult
+CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner, PRInt32 aFlag)
+{
+ static const PRUnichar theTerminalsChars[] =
{ PRUnichar('\n'), PRUnichar('\r'), PRUnichar('&'), PRUnichar('<'),
PRUnichar(0) };
static const nsReadEndCondition theEndCondition(theTerminalsChars);
- nsresult result=NS_OK;
- PRBool done=PR_FALSE;
+ nsresult result = NS_OK;
+ PRBool done = PR_FALSE;
nsScannerIterator origin, start, end;
-
+
// Start scanning after the first character, because we know it to
// be part of this text token (we wouldn't have come here if it weren't)
aScanner.CurrentPosition(origin);
@@ -598,26 +515,24 @@ nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag)
aScanner.SetPosition(++start);
- while((NS_OK==result) && (!done)) {
- result=aScanner.ReadUntil(start, end, theEndCondition, PR_FALSE);
- if(NS_OK==result) {
- result=aScanner.Peek(aChar);
+ while (NS_OK == result && !done) {
+ result = aScanner.ReadUntil(start, end, theEndCondition, PR_FALSE);
+ if (NS_OK == result) {
+ result = aScanner.Peek(aChar);
- if(((kCR==aChar) || (kNewLine==aChar)) && (NS_OK==result)) {
- result=aScanner.GetChar(aChar); //strip off the char
+ if (NS_OK == result && (kCR == aChar || kNewLine == aChar)) {
+ result = aScanner.GetChar(aChar); // Strip off the char
PRUnichar theNextChar;
- result=aScanner.Peek(theNextChar); //then see what's next.
- switch(aChar) {
+ result = aScanner.Peek(theNextChar); // Then see what's next.
+ switch (aChar) {
case kCR:
- // result=aScanner.GetChar(aChar);
- if(kLF==theNextChar) {
- // If the "\r" is followed by a "\n", don't replace it and
+ if (kLF == theNextChar) {
+ // If the "\r" is followed by a "\n", don't replace it and
// let it be ignored by the layout system
end.advance(2);
- result=aScanner.GetChar(theNextChar);
- }
- else {
- // If it standalone, replace the "\r" with a "\n" so that
+ result = aScanner.GetChar(theNextChar);
+ } else {
+ // If it standalone, replace the "\r" with a "\n" so that
// it will be considered by the layout system
aScanner.ReplaceCharacter(end, kLF);
++end;
@@ -628,12 +543,13 @@ nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag)
++end;
++mNewlineCount;
break;
- } //switch
+ }
+ } else {
+ done = PR_TRUE;
}
- else done=PR_TRUE;
}
}
-
+
aScanner.BindSubstring(mTextValue, origin, end);
return result;
@@ -654,16 +570,19 @@ nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag)
* @param aFlushTokens -- PR_TRUE if we found the terminal tag.
* @return error result
*/
-nsresult CTextToken::ConsumeCharacterData(PRBool aConservativeConsume,
- PRBool aIgnoreComments,
- nsScanner& aScanner,
- const nsAString& aEndTagName,
- PRInt32 aFlag,
- PRBool& aFlushTokens) {
- nsresult result=NS_OK;
- nsScannerIterator theStartOffset, theCurrOffset, theTermStrPos, theStartCommentPos, theAltTermStrPos, endPos;
- PRBool done=PR_FALSE;
- PRBool theLastIteration=PR_FALSE;
+nsresult
+CTextToken::ConsumeCharacterData(PRBool aConservativeConsume,
+ PRBool aIgnoreComments,
+ nsScanner& aScanner,
+ const nsAString& aEndTagName,
+ PRInt32 aFlag,
+ PRBool& aFlushTokens)
+{
+ nsresult result = NS_OK;
+ nsScannerIterator theStartOffset, theCurrOffset, theTermStrPos,
+ theStartCommentPos, theAltTermStrPos, endPos;
+ PRBool done = PR_FALSE;
+ PRBool theLastIteration = PR_FALSE;
aScanner.CurrentPosition(theStartOffset);
theCurrOffset = theStartOffset;
@@ -672,31 +591,39 @@ nsresult CTextToken::ConsumeCharacterData(PRBool aConservativeConsume,
// ALGORITHM: *** The performance is based on correctness of the document ***
// 1. Look for a '<' character. This could be
- // a) Start of a comment (' between the terminal string and ' . But record terminal string's
- // offset if this is the first premature terminal string, and update the current offset to the terminal
- // string (prematured) offset and goto step 1.
+ // a) Start of a comment (' between the terminal string and
+ // ' . But record
+ // terminal string's offset if this is the first premature terminal
+ // string, and update the current offset to the terminal string
+ // (prematured) offset and goto step 1.
// 4. Amen...If you found a terminal string and '-->'. Otherwise goto step 1.
- // 5. If the end of the document is reached and if we still don't have the condition in step 4. then
- // assume that the prematured terminal string is the actual terminal string and goto step 1. This
- // will be our last iteration. If there is no premature terminal string and we're being
- // conservative in our consumption (aConservativeConsume), then don't consume anything
- // from the scanner. Otherwise, we consume all the way until the end (for ).
+ // 5. If the end of the document is reached and if we still don't have the
+ // condition in step 4. then assume that the prematured terminal string
+ // is the actual terminal string and goto step 1. This will be our last
+ // iteration. If there is no premature terminal string and we're being
+ // conservative in our consumption (aConservativeConsume), then don't
+ // consume anything from the scanner. Otherwise, we consume all the way
+ // until the end (for ).
NS_NAMED_LITERAL_STRING(ltslash, "");
const nsString theTerminalString = ltslash + aEndTagName;
- PRUint32 termStrLen=theTerminalString.Length();
- while((result == NS_OK) && !done) {
+ PRUint32 termStrLen = theTerminalString.Length();
+ while (result == NS_OK && !done) {
PRBool found = PR_FALSE;
- nsScannerIterator gtOffset,ltOffset = theCurrOffset;
+ nsScannerIterator gtOffset, ltOffset = theCurrOffset;
while (FindCharInReadable(PRUnichar(kLessThan), ltOffset, endPos) &&
((PRUint32)ltOffset.size_forward() >= termStrLen ||
Distance(ltOffset, endPos) >= termStrLen)) {
@@ -706,14 +633,14 @@ nsresult CTextToken::ConsumeCharacterData(PRBool aConservativeConsume,
nsScannerIterator start(ltOffset), end(ltOffset);
end.advance(termStrLen);
- if (CaseInsensitiveFindInReadable(theTerminalString,start,end) &&
- (end == endPos || (*end == '>' || *end == ' ' ||
- *end == '\t' || *end == '\n' ||
+ if (CaseInsensitiveFindInReadable(theTerminalString, start, end) &&
+ (end == endPos || (*end == '>' || *end == ' ' ||
+ *end == '\t' || *end == '\n' ||
*end == '\r' || *end == '\b'))) {
gtOffset = end;
// Note that aIgnoreComments is only not set for or ...permit flushing -> Ref: Bug 22485
- aFlushTokens=PR_TRUE;
+ aFlushTokens = PR_TRUE;
done = PR_TRUE;
- }
- else {
+ } else {
// We end up here if:
// a) when the buffer runs out ot data.
// b) when the terminal string is not found.
- if(!aScanner.IsIncremental()) {
- if(theAltTermStrPos != endPos && aConservativeConsume) {
- // If you're here it means..we hit the rock bottom and therefore switch to plan B.
+ if (!aScanner.IsIncremental()) {
+ if (theAltTermStrPos != endPos && aConservativeConsume) {
+ // If you're here it means that we hit the rock bottom and therefore
+ // switch to plan B.
theCurrOffset = theAltTermStrPos;
theLastIteration = PR_TRUE;
- }
- else if (!aConservativeConsume) {
+ } else if (!aConservativeConsume) {
done = PR_TRUE; // Do this to fix Bug. 35456
result = kFakeEndTag;
aScanner.BindSubstring(mTextValue, theStartOffset, endPos);
aScanner.SetPosition(endPos);
- }
- else {
+ } else {
done = PR_TRUE;
result = kFakeEndTag;
// We need to bind our value to a non-empty string.
aScanner.BindSubstring(mTextValue, theStartOffset, theStartOffset);
}
- }
- else {
- result=kEOF;
+ } else {
+ result = kEOF;
}
}
}
@@ -812,12 +737,13 @@ nsresult CTextToken::ConsumeCharacterData(PRBool aConservativeConsume,
* @param aFlushTokens -- PR_TRUE if we found the terminal tag.
* @return error result
*/
-nsresult CTextToken::ConsumeParsedCharacterData(PRBool aDiscardFirstNewline,
- PRBool aConservativeConsume,
- nsScanner& aScanner,
- const nsAString& aEndTagName,
- PRInt32 aFlag,
- PRBool& aFound)
+nsresult
+CTextToken::ConsumeParsedCharacterData(PRBool aDiscardFirstNewline,
+ PRBool aConservativeConsume,
+ nsScanner& aScanner,
+ const nsAString& aEndTagName,
+ PRInt32 aFlag,
+ PRBool& aFound)
{
// This function is fairly straightforward except if there is no terminating
// string. If there is, we simply loop through all of the entities, reducing
@@ -856,10 +782,10 @@ nsresult CTextToken::ConsumeParsedCharacterData(PRBool aDiscardFirstNewline,
// Note that if we're already at the end of the document, the ConsumeUntil
// will fail, and we'll do the right thing.
do {
- result = ConsumeUntil(theContent, mNewlineCount, aScanner,
+ result = ConsumeUntil(theContent, mNewlineCount, aScanner,
theEndCondition, PR_TRUE, PR_FALSE, aFlag);
- if (aDiscardFirstNewline &&
+ if (aDiscardFirstNewline &&
(NS_SUCCEEDED(result) || !aScanner.IsIncremental()) &&
!(aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
// Check if the very first character is a newline, and if so discard it.
@@ -905,8 +831,7 @@ nsresult CTextToken::ConsumeParsedCharacterData(PRBool aDiscardFirstNewline,
}
// else we take everything we consumed.
mTextValue.Rebind(theContent.str());
- }
- else {
+ } else {
aFound = PR_FALSE;
}
@@ -926,9 +851,9 @@ nsresult CTextToken::ConsumeParsedCharacterData(PRBool aDiscardFirstNewline,
nsScannerIterator start(currPos), end(currPos);
end.advance(termStrLen);
- if (CaseInsensitiveFindInReadable(theTerminalString,start,end)) {
- if (end != endPos && (*end == '>' || *end == ' ' ||
- *end == '\t' || *end == '\n' ||
+ if (CaseInsensitiveFindInReadable(theTerminalString, start, end)) {
+ if (end != endPos && (*end == '>' || *end == ' ' ||
+ *end == '\t' || *end == '\n' ||
*end == '\r' || *end == '\b')) {
aFound = PR_TRUE;
mTextValue.Rebind(theContent.str());
@@ -947,7 +872,7 @@ nsresult CTextToken::ConsumeParsedCharacterData(PRBool aDiscardFirstNewline,
nsScannerIterator start(currPos), end(currPos);
end.advance(commentStartLen);
- if (CaseInsensitiveFindInReadable(commentStart,start,end)) {
+ if (CaseInsensitiveFindInReadable(commentStart, start, end)) {
CCommentToken consumer; // stack allocated.
// CCommentToken expects us to be on the '-'
@@ -955,17 +880,17 @@ nsresult CTextToken::ConsumeParsedCharacterData(PRBool aDiscardFirstNewline,
// In quirks mode we consume too many things as comments, so pretend
// that we're not by modifying aFlag.
- result = consumer.Consume(*currPos, aScanner,
- (aFlag & ~NS_IPARSER_FLAG_QUIRKS_MODE) | NS_IPARSER_FLAG_STRICT_MODE);
+ result = consumer.Consume(*currPos, aScanner,
+ (aFlag & ~NS_IPARSER_FLAG_QUIRKS_MODE) |
+ NS_IPARSER_FLAG_STRICT_MODE);
if (kEOF == result) {
- return kEOF; // this can only happen if we're really out of space.
- }
- else if (kNotAComment == result) {
+ // This can only happen if we're really out of space.
+ return kEOF;
+ } else if (kNotAComment == result) {
// Fall through and consume this as text.
aScanner.CurrentPosition(currPos);
aScanner.SetPosition(currPos.advance(1));
- }
- else {
+ } else {
consumer.AppendSourceTo(theContent.writable());
mNewlineCount += consumer.GetNewlineCount();
continue;
@@ -982,7 +907,8 @@ nsresult CTextToken::ConsumeParsedCharacterData(PRBool aDiscardFirstNewline,
return result;
}
-void CTextToken::CopyTo(nsAString& aStr)
+void
+CTextToken::CopyTo(nsAString& aStr)
{
nsScannerIterator start, end;
mTextValue.BeginReading(start);
@@ -990,108 +916,100 @@ void CTextToken::CopyTo(nsAString& aStr)
CopyUnicodeTo(start, end, aStr);
}
-const nsSubstring& CTextToken::GetStringValue(void)
+const nsSubstring& CTextToken::GetStringValue()
{
return mTextValue.AsString();
}
-void CTextToken::Bind(nsScanner* aScanner, nsScannerIterator& aStart, nsScannerIterator& aEnd)
+void
+CTextToken::Bind(nsScanner* aScanner, nsScannerIterator& aStart,
+ nsScannerIterator& aEnd)
{
aScanner->BindSubstring(mTextValue, aStart, aEnd);
}
-void CTextToken::Bind(const nsAString& aStr)
+void
+CTextToken::Bind(const nsAString& aStr)
{
mTextValue.Rebind(aStr);
}
-/*
- * default constructor
- *
- * @update vidur 11/12/98
- * @param aName -- string to init token name with
- * @return
- */
-CCDATASectionToken::CCDATASectionToken(eHTMLTags aTag) : CHTMLToken(aTag) {
+CCDATASectionToken::CCDATASectionToken(eHTMLTags aTag)
+ : CHTMLToken(aTag)
+{
}
-
-/*
- * string based constructor
- *
- * @update vidur 11/12/98
- * @param aName -- string to init token name with
- * @return
- */
-CCDATASectionToken::CCDATASectionToken(const nsAString& aName) : CHTMLToken(eHTMLTag_unknown) {
+CCDATASectionToken::CCDATASectionToken(const nsAString& aName)
+ : CHTMLToken(eHTMLTag_unknown)
+{
mTextValue.Assign(aName);
}
-/*
- *
- * @update vidur 11/12/98
- * @param
- * @return
- */
-PRInt32 CCDATASectionToken::GetTokenType(void) {
+PRInt32
+CCDATASectionToken::GetTokenType()
+{
return eToken_cdatasection;
}
/*
* Consume as much marked test from scanner as possible.
+ * Note: This has to handle case: "", in addition to ""
*
- * @update rgess 12/15/99: had to handle case: "", in addition to "".
* @param aChar -- last char consumed from stream
* @param aScanner -- controller of underlying input source
* @return error result
*/
-nsresult CCDATASectionToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag) {
- static const PRUnichar theTerminalsChars[] =
+nsresult
+CCDATASectionToken::Consume(PRUnichar aChar, nsScanner& aScanner,
+ PRInt32 aFlag)
+{
+ static const PRUnichar theTerminalsChars[] =
{ PRUnichar('\r'), PRUnichar('\n'), PRUnichar(']'), PRUnichar(0) };
static const nsReadEndCondition theEndCondition(theTerminalsChars);
- nsresult result=NS_OK;
- PRBool done=PR_FALSE;
+ nsresult result = NS_OK;
+ PRBool done = PR_FALSE;
- while((NS_OK==result) && (!done)) {
- result=aScanner.ReadUntil(mTextValue,theEndCondition,PR_FALSE);
- if(NS_OK==result) {
- result=aScanner.Peek(aChar);
- if((kCR==aChar) && (NS_OK==result)) {
- result=aScanner.GetChar(aChar); //strip off the \r
- result=aScanner.Peek(aChar); //then see what's next.
- if(NS_OK==result) {
+ while (NS_OK == result && !done) {
+ result = aScanner.ReadUntil(mTextValue, theEndCondition, PR_FALSE);
+ if (NS_OK == result) {
+ result = aScanner.Peek(aChar);
+ if (kCR == aChar && NS_OK == result) {
+ result = aScanner.GetChar(aChar); // Strip off the \r
+ result = aScanner.Peek(aChar); // Then see what's next.
+ if (NS_OK == result) {
switch(aChar) {
case kCR:
- result=aScanner.GetChar(aChar); //strip off the \r
+ result = aScanner.GetChar(aChar); // Strip off the \r
mTextValue.AppendLiteral("\n\n");
mNewlineCount += 2;
break;
+
case kNewLine:
- //which means we saw \r\n, which becomes \n
- result=aScanner.GetChar(aChar); //strip off the \n
- //now fall through on purpose...
+ // Which means we saw \r\n, which becomes \n
+ result = aScanner.GetChar(aChar); // Strip off the \n
+
+ // Fall through...
default:
mTextValue.AppendLiteral("\n");
mNewlineCount++;
break;
- } //switch
- } //if
- }
- else if (kNewLine == aChar) {
- result=aScanner.GetChar(aChar);
+ }
+ }
+ } else if (kNewLine == aChar) {
+ result = aScanner.GetChar(aChar);
mTextValue.Append(aChar);
++mNewlineCount;
- }
- else if (kRightSquareBracket == aChar) {
+ } else if (kRightSquareBracket == aChar) {
PRBool canClose = PR_FALSE;
- result=aScanner.GetChar(aChar); //strip off the ]
+ result = aScanner.GetChar(aChar); // Strip off the ]
mTextValue.Append(aChar);
- result=aScanner.Peek(aChar); //then see what's next.
- if((NS_OK==result) && (kRightSquareBracket==aChar)) {
- result=aScanner.GetChar(aChar); //strip off the second ]
+ result = aScanner.Peek(aChar); // Then see what's next.
+ if (NS_OK == result && kRightSquareBracket == aChar) {
+ result = aScanner.GetChar(aChar); // Strip off the second ]
mTextValue.Append(aChar);
canClose = PR_TRUE;
}
+
// The goal here is to not lose data from the page when encountering
// markup like: . This means that in normal parsing, we
// allow ']' to end the marked section and just drop everything between
@@ -1100,21 +1018,23 @@ nsresult CCDATASectionToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt3
// CDATA sections at all bearable, we need to somewhat enforce the ']]>'
// terminator for marked sections. So make the tokenization somewhat
// different when in view-source _and_ dealing with a CDATA section.
+ // XXX We should remember this StringBeginsWith test.
PRBool inCDATA = (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE) &&
StringBeginsWith(mTextValue, NS_LITERAL_STRING("[CDATA["));
if (inCDATA) {
result = aScanner.Peek(aChar);
} else {
- nsAutoString dummy; // skip any bad data
- result=aScanner.ReadUntil(dummy,kGreaterThan,PR_FALSE);
+ nsAutoString dummy; // Skip any bad data
+ result = aScanner.ReadUntil(dummy, kGreaterThan, PR_FALSE);
}
- if (NS_OK==result &&
+ if (NS_OK == result &&
(!inCDATA || (canClose && kGreaterThan == aChar))) {
- result=aScanner.GetChar(aChar); //strip off the >
- done=PR_TRUE;
+ result = aScanner.GetChar(aChar); // Strip off the >
+ done = PR_TRUE;
}
+ } else {
+ done = PR_TRUE;
}
- else done=PR_TRUE;
}
}
@@ -1130,39 +1050,27 @@ nsresult CCDATASectionToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt3
return result;
}
-const nsSubstring& CCDATASectionToken::GetStringValue(void)
+const nsSubstring&
+CCDATASectionToken::GetStringValue()
{
return mTextValue;
}
-/*
- * default constructor
- *
- * @param aName -- string to init token name with
- * @return
- */
-CMarkupDeclToken::CMarkupDeclToken() : CHTMLToken(eHTMLTag_markupDecl) {
+CMarkupDeclToken::CMarkupDeclToken()
+ : CHTMLToken(eHTMLTag_markupDecl)
+{
}
-
-/*
- * string based constructor
- *
- * @param aName -- string to init token name with
- * @return
- */
-CMarkupDeclToken::CMarkupDeclToken(const nsAString& aName) : CHTMLToken(eHTMLTag_markupDecl) {
+CMarkupDeclToken::CMarkupDeclToken(const nsAString& aName)
+ : CHTMLToken(eHTMLTag_markupDecl)
+{
mTextValue.Rebind(aName);
}
-
-/*
- *
- * @param
- * @return
- */
-PRInt32 CMarkupDeclToken::GetTokenType(void) {
+PRInt32
+CMarkupDeclToken::GetTokenType()
+{
return eToken_markupDecl;
}
@@ -1175,43 +1083,45 @@ PRInt32 CMarkupDeclToken::GetTokenType(void) {
* @param aScanner -- controller of underlying input source
* @return error result
*/
-nsresult CMarkupDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag) {
- static const PRUnichar theTerminalsChars[] =
+nsresult
+CMarkupDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,
+ PRInt32 aFlag)
+{
+ static const PRUnichar theTerminalsChars[] =
{ PRUnichar('\n'), PRUnichar('\r'), PRUnichar('\''), PRUnichar('"'),
PRUnichar('>'),
PRUnichar(0) };
static const nsReadEndCondition theEndCondition(theTerminalsChars);
- nsresult result=NS_OK;
- PRBool done=PR_FALSE;
- PRUnichar quote=0;
+ nsresult result = NS_OK;
+ PRBool done = PR_FALSE;
+ PRUnichar quote = 0;
nsScannerIterator origin, start, end;
aScanner.CurrentPosition(origin);
start = origin;
- while((NS_OK==result) && (!done)) {
+ while (NS_OK == result && !done) {
aScanner.SetPosition(start);
- result=aScanner.ReadUntil(start, end, theEndCondition, PR_FALSE);
- if(NS_OK==result) {
- result=aScanner.Peek(aChar);
+ result = aScanner.ReadUntil(start, end, theEndCondition, PR_FALSE);
+ if (NS_OK == result) {
+ result = aScanner.Peek(aChar);
- if(NS_OK==result) {
- PRUnichar theNextChar=0;
- if ((kCR==aChar) || (kNewLine==aChar)) {
- result=aScanner.GetChar(aChar); //strip off the char
- result=aScanner.Peek(theNextChar); //then see what's next.
+ if (NS_OK == result) {
+ PRUnichar theNextChar = 0;
+ if (kCR == aChar || kNewLine == aChar) {
+ result = aScanner.GetChar(aChar); // Strip off the char
+ result = aScanner.Peek(theNextChar); // Then see what's next.
}
switch(aChar) {
case kCR:
- // result=aScanner.GetChar(aChar);
- if(kLF==theNextChar) {
- // If the "\r" is followed by a "\n", don't replace it and
+ // result = aScanner.GetChar(aChar);
+ if (kLF == theNextChar) {
+ // If the "\r" is followed by a "\n", don't replace it and
// let it be ignored by the layout system
end.advance(2);
- result=aScanner.GetChar(theNextChar);
- }
- else {
- // If it standalone, replace the "\r" with a "\n" so that
+ result = aScanner.GetChar(theNextChar);
+ } else {
+ // If it standalone, replace the "\r" with a "\n" so that
// it will be considered by the layout system
aScanner.ReplaceCharacter(end, kLF);
++end;
@@ -1238,21 +1148,22 @@ nsresult CMarkupDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32
++end;
} else {
start = end;
- ++start; // Note that start is wrong after this, we just avoid temp var
+ // Note that start is wrong after this, we just avoid temp var
+ ++start;
aScanner.SetPosition(start); // Skip the >
- done=PR_TRUE;
+ done = PR_TRUE;
}
break;
default:
- NS_ABORT_IF_FALSE(0,"should not happen, switch is missing cases?");
+ NS_ABORT_IF_FALSE(0, "should not happen, switch is missing cases?");
break;
- } //switch
+ }
start = end;
+ } else {
+ done = PR_TRUE;
}
- else done=PR_TRUE;
- } // if read until !ok
- } // while
-
+ }
+ }
aScanner.BindSubstring(mTextValue, origin, end);
if (kEOF == result) {
@@ -1266,47 +1177,38 @@ nsresult CMarkupDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32
return result;
}
-const nsSubstring& CMarkupDeclToken::GetStringValue(void)
+const nsSubstring&
+CMarkupDeclToken::GetStringValue()
{
return mTextValue.AsString();
}
-/*
- * Default constructor
- *
- * @update gess 3/25/98
- * @param aName -- string to init token name with
- * @return
- */
-CCommentToken::CCommentToken() : CHTMLToken(eHTMLTag_comment) {
+CCommentToken::CCommentToken()
+ : CHTMLToken(eHTMLTag_comment)
+{
}
-
-/*
- * Copy constructor
- *
- * @update gess 3/25/98
- * @param
- * @return
- */
-CCommentToken::CCommentToken(const nsAString& aName) : CHTMLToken(eHTMLTag_comment) {
+CCommentToken::CCommentToken(const nsAString& aName)
+ : CHTMLToken(eHTMLTag_comment)
+{
mComment.Rebind(aName);
}
-void CCommentToken::AppendSourceTo(nsAString& anOutputString){
+void
+CCommentToken::AppendSourceTo(nsAString& anOutputString)
+{
AppendUnicodeTo(mCommentDecl, anOutputString);
}
-static PRBool IsCommentEnd(
- const nsScannerIterator& aCurrent,
- const nsScannerIterator& aEnd,
- nsScannerIterator& aGt)
+static PRBool
+IsCommentEnd(const nsScannerIterator& aCurrent, const nsScannerIterator& aEnd,
+ nsScannerIterator& aGt)
{
nsScannerIterator current = aCurrent;
PRInt32 dashes = 0;
- while ((current != aEnd) && (dashes != 2)) {
+ while (current != aEnd && dashes != 2) {
if (*current == kGreaterThan) {
aGt = current;
return PR_TRUE;
@@ -1322,7 +1224,8 @@ static PRBool IsCommentEnd(
return PR_FALSE;
}
-nsresult CCommentToken::ConsumeStrictComment(nsScanner& aScanner)
+nsresult
+CCommentToken::ConsumeStrictComment(nsScanner& aScanner)
{
//
/*********************************************************
@@ -1345,14 +1248,14 @@ nsresult CCommentToken::ConsumeStrictComment(nsScanner& aScanner)
++current != end) {
nsScannerIterator currentEnd = end;
PRBool balancedComment = PR_FALSE;
- static NS_NAMED_LITERAL_STRING(dashes,"--");
+ static NS_NAMED_LITERAL_STRING(dashes, "--");
beginData = current;
while (FindInReadable(dashes, current, currentEnd)) {
current.advance(2);
balancedComment = !balancedComment; // We need to match '--' with '--'
-
+
if (balancedComment && IsCommentEnd(current, end, gt)) {
// done
current.advance(-2);
@@ -1377,7 +1280,7 @@ nsresult CCommentToken::ConsumeStrictComment(nsScanner& aScanner)
aScanner.CurrentPosition(current);
beginData = current;
if (FindCharInReadable('>', current, end)) {
- aScanner.BindSubstring(mComment, beginData, current);
+ aScanner.BindSubstring(mComment, beginData, current);
aScanner.BindSubstring(mCommentDecl, lt, ++current);
aScanner.SetPosition(current);
return NS_OK;
@@ -1399,7 +1302,8 @@ nsresult CCommentToken::ConsumeStrictComment(nsScanner& aScanner)
return kNotAComment;
}
-nsresult CCommentToken::ConsumeQuirksComment(nsScanner& aScanner)
+nsresult
+CCommentToken::ConsumeQuirksComment(nsScanner& aScanner)
{
//
/*********************************************************
@@ -1410,7 +1314,7 @@ nsresult CCommentToken::ConsumeQuirksComment(nsScanner& aScanner)
nsScannerIterator end, current;
aScanner.EndReading(end);
aScanner.CurrentPosition(current);
- nsScannerIterator beginData = current,
+ nsScannerIterator beginData = current,
beginLastMinus = end,
bestAltCommentEnd = end,
lt = current;
@@ -1429,7 +1333,7 @@ nsresult CCommentToken::ConsumeQuirksComment(nsScanner& aScanner)
// Long form comment
nsScannerIterator currentEnd = end, gt = end;
-
+
// Find the end of the comment
while (FindCharInReadable(kGreaterThan, current, currentEnd)) {
gt = current;
@@ -1456,7 +1360,7 @@ nsresult CCommentToken::ConsumeQuirksComment(nsScanner& aScanner)
} else if (current == beginLastMinus) {
goodComment = PR_TRUE;
}
-
+
if (goodComment) {
// done
aScanner.BindSubstring(mComment, beginData, ++current);
@@ -1468,8 +1372,8 @@ nsresult CCommentToken::ConsumeQuirksComment(nsScanner& aScanner)
current = ++gt;
currentEnd = end;
}
- } //while
-
+ }
+
if (aScanner.IsIncremental()) {
// We got here because we saw the beginning of a comment,
// but not yet the end, and we are still loading the page. In that
@@ -1480,11 +1384,13 @@ nsresult CCommentToken::ConsumeQuirksComment(nsScanner& aScanner)
return kEOF;
}
- // If you're here, then we're in a special state.
- // The problem at hand is that we've hit the end of the document without finding the normal endcomment delimiter "-->".
- // In this case, the first thing we try is to see if we found an alternate endcomment delimiter ">".
- // If so, rewind just pass that, and use everything up to that point as your comment.
- // If not, the document has no end comment and should be treated as one big comment.
+ // If you're here, then we're in a special state.
+ // The problem at hand is that we've hit the end of the document without
+ // finding the normal endcomment delimiter "-->". In this case, the
+ // first thing we try is to see if we found an alternate endcomment
+ // delimiter ">". If so, rewind just pass that, and use everything up
+ // to that point as your comment. If not, the document has no end
+ // comment and should be treated as one big comment.
gt = bestAltCommentEnd;
aScanner.BindSubstring(mComment, beginData, gt);
if (gt != end) {
@@ -1495,7 +1401,7 @@ nsresult CCommentToken::ConsumeQuirksComment(nsScanner& aScanner)
return NS_OK;
}
}
-
+
// This could be short form of comment
// Find the end of the comment
current = beginData;
@@ -1521,8 +1427,7 @@ nsresult CCommentToken::ConsumeQuirksComment(nsScanner& aScanner)
if (current != gt) {
aScanner.BindSubstring(mComment, beginData, ++current);
- }
- else {
+ } else {
// Bind mComment to an empty string (note that if current == gt,
// then current == beginData). We reach this for
aScanner.BindSubstring(mComment, beginData, current);
@@ -1543,77 +1448,64 @@ nsresult CCommentToken::ConsumeQuirksComment(nsScanner& aScanner)
}
/*
- * Consume the identifier portion of the comment.
+ * Consume the identifier portion of the comment.
* Note that we've already eaten the "AsString();
}
/*
- * Consume as many cr/lf pairs as you can find.
- *
- * @update gess 3/25/98
+ * Consume one newline (cr/lf pair).
+ *
* @param aChar -- last char consumed from stream
* @param aScanner -- controller of underlying input source
* @return error result
*/
-nsresult CNewlineToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag) {
-
-/*******************************************************************
-
- Here's what the HTML spec says about newlines:
-
- "A line break is defined to be a carriage return (
),
- a line feed (
), or a carriage return/line feed pair.
- All line breaks constitute white space."
-
- *******************************************************************/
-
+nsresult
+CNewlineToken::Consume(PRUnichar aChar, nsScanner& aScanner, PRInt32 aFlag)
+{
+ /*
+ * Here's what the HTML spec says about newlines:
+ *
+ * "A line break is defined to be a carriage return (
),
+ * a line feed (
), or a carriage return/line feed pair.
+ * All line breaks constitute white space."
+ */
PRUnichar theChar;
- nsresult result=aScanner.Peek(theChar);
+ nsresult result = aScanner.Peek(theChar);
- if(NS_OK==result) {
+ if (NS_OK == result) {
switch(aChar) {
case kNewLine:
- if(kCR==theChar) {
- result=aScanner.GetChar(theChar);
+ if (kCR == theChar) {
+ result = aScanner.GetChar(theChar);
}
break;
- case kCR:
- //convert CRLF into just CR
- if(kNewLine==theChar) {
- result=aScanner.GetChar(theChar);
+
+ case kCR:
+ // Convert CRLF into just CR
+ if (kNewLine == theChar) {
+ result = aScanner.GetChar(theChar);
}
break;
+
default:
break;
}
@@ -1681,110 +1573,83 @@ nsresult CNewlineToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFl
return result;
}
-/*
- * default constructor
- *
- * @update gess 3/25/98
- * @param aName -- string to init token name with
- * @return
- */
-CAttributeToken::CAttributeToken() : CHTMLToken(eHTMLTag_unknown) {
- mHasEqualWithoutValue=PR_FALSE;
+CAttributeToken::CAttributeToken()
+ : CHTMLToken(eHTMLTag_unknown)
+{
+ mHasEqualWithoutValue = PR_FALSE;
}
/*
- * string based constructor
- *
- * @update gess 3/25/98
- * @param aName -- string value to init token name with
- * @return
+ * String based constructor
*/
-CAttributeToken::CAttributeToken(const nsAString& aName) : CHTMLToken(eHTMLTag_unknown) {
+CAttributeToken::CAttributeToken(const nsAString& aName)
+ : CHTMLToken(eHTMLTag_unknown)
+{
mTextValue.writable().Assign(aName);
- mHasEqualWithoutValue=PR_FALSE;
+ mHasEqualWithoutValue = PR_FALSE;
}
/*
- * construct initializing data to
- * key value pair
- *
- * @update gess 3/25/98
- * @param aName -- string value to init token name with
- * @return
+ * construct initializing data to key value pair
*/
-CAttributeToken::CAttributeToken(const nsAString& aKey, const nsAString& aName) : CHTMLToken(eHTMLTag_unknown) {
+CAttributeToken::CAttributeToken(const nsAString& aKey, const nsAString& aName)
+ : CHTMLToken(eHTMLTag_unknown)
+{
mTextValue.writable().Assign(aName);
mTextKey.Rebind(aKey);
- mHasEqualWithoutValue=PR_FALSE;
+ mHasEqualWithoutValue = PR_FALSE;
}
-/*
- *
- *
- * @update gess 3/25/98
- * @param
- * @return
- */
-PRInt32 CAttributeToken::GetTokenType(void) {
+PRInt32
+CAttributeToken::GetTokenType()
+{
return eToken_attribute;
}
-const nsSubstring& CAttributeToken::GetStringValue(void)
+const nsSubstring&
+CAttributeToken::GetStringValue()
{
return mTextValue.str();
}
-
-/*
- *
- *
- * @update rickg 6June2000
- * @param anOutputString will recieve the result
- * @return nada
- */
-void CAttributeToken::GetSource(nsString& anOutputString){
+
+void
+CAttributeToken::GetSource(nsString& anOutputString)
+{
anOutputString.Truncate();
AppendSourceTo(anOutputString);
}
-/*
- *
- *
- * @update rickg 6June2000
- * @param result appended to the output string.
- * @return nada
- */
-void CAttributeToken::AppendSourceTo(nsAString& anOutputString){
+void
+CAttributeToken::AppendSourceTo(nsAString& anOutputString)
+{
AppendUnicodeTo(mTextKey, anOutputString);
- if(mTextValue.str().Length() || mHasEqualWithoutValue)
+ if (mTextValue.str().Length() || mHasEqualWithoutValue) {
anOutputString.AppendLiteral("=");
+ }
anOutputString.Append(mTextValue.str());
// anOutputString.AppendLiteral(";");
}
/*
- * This general purpose method is used when you want to
- * consume a known quoted string.
- *
- * @param aScanner -- controller of underlying input source
- * @param aTerminalChars -- characters that stop consuming attribute.
- * @param aFlag - contains information such as |dtd mode|view mode|doctype|etc...
- * @return error result
+ * This general purpose method is used when you want to
+ * consume a known quoted string.
*/
-static
-nsresult ConsumeQuotedString(PRUnichar aChar,
- nsScannerSharedSubstring& aString,
- PRInt32& aNewlineCount,
- nsScanner& aScanner,
- PRInt32 aFlag)
+static nsresult
+ConsumeQuotedString(PRUnichar aChar,
+ nsScannerSharedSubstring& aString,
+ PRInt32& aNewlineCount,
+ nsScanner& aScanner,
+ PRInt32 aFlag)
{
- NS_ASSERTION(aChar==kQuote || aChar==kApostrophe,"char is neither quote nor apostrophe");
- // hold onto this in case this is an unterminated string literal
+ NS_ASSERTION(aChar == kQuote || aChar == kApostrophe,
+ "char is neither quote nor apostrophe");
+ // Hold onto this in case this is an unterminated string literal
PRUint32 origLen = aString.str().Length();
- static const PRUnichar theTerminalCharsQuote[] = {
+ static const PRUnichar theTerminalCharsQuote[] = {
PRUnichar(kQuote), PRUnichar('&'), PRUnichar(kCR),
PRUnichar(kNewLine), PRUnichar(0) };
- static const PRUnichar theTerminalCharsApostrophe[] = {
+ static const PRUnichar theTerminalCharsApostrophe[] = {
PRUnichar(kApostrophe), PRUnichar('&'), PRUnichar(kCR),
PRUnichar(kNewLine), PRUnichar(0) };
static const nsReadEndCondition
@@ -1794,25 +1659,26 @@ nsresult ConsumeQuotedString(PRUnichar aChar,
// Assume Quote to init to something
const nsReadEndCondition *terminateCondition = &theTerminateConditionQuote;
- if (aChar==kApostrophe)
+ if (aChar == kApostrophe) {
terminateCondition = &theTerminateConditionApostrophe;
-
- nsresult result=NS_OK;
+ }
+
+ nsresult result = NS_OK;
nsScannerIterator theOffset;
aScanner.CurrentPosition(theOffset);
- result=ConsumeUntil(aString, aNewlineCount, aScanner,
+ result = ConsumeUntil(aString, aNewlineCount, aScanner,
*terminateCondition, PR_TRUE, PR_TRUE, aFlag);
- if(NS_SUCCEEDED(result)) {
+ if (NS_SUCCEEDED(result)) {
result = aScanner.GetChar(aChar); // aChar should be " or '
}
// Ref: Bug 35806
// A back up measure when disaster strikes...
// Ex '), PRUnichar('<'),
PRUnichar('\b'), PRUnichar('\''),
PRUnichar('/'), PRUnichar(0) };
static const nsReadEndCondition theEndCondition(theTerminalsChars);
nsScannerIterator start, end;
- result=aScanner.ReadUntil(start,end,theEndCondition,PR_FALSE);
+ result = aScanner.ReadUntil(start, end, theEndCondition, PR_FALSE);
if (!(aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
aScanner.BindSubstring(mTextKey, start, end);
- }
- else if (kEOF == result && wsstart != end) {
- //Capture all of the text (from the beginning of the whitespace to the
- //end of the document).
+ } else if (kEOF == result && wsstart != end) {
+ // Capture all of the text (from the beginning of the whitespace to the
+ // end of the document).
aScanner.BindSubstring(mTextKey, wsstart, end);
}
- //now it's time to Consume the (optional) value...
- if (NS_OK==result) {
+ // Now it's time to Consume the (optional) value...
+ if (NS_OK == result) {
if (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE) {
result = aScanner.ReadWhitespace(start, wsend, mNewlineCount);
aScanner.BindSubstring(mTextKey, wsstart, wsend);
- }
- else {
+ } else {
result = aScanner.SkipWhitespace(mNewlineCount);
}
- if (NS_OK==result) {
- result=aScanner.Peek(aChar); //Skip ahead until you find an equal sign or a '>'...
- if (NS_OK==result) {
- if (kEqual==aChar){
- result=aScanner.GetChar(aChar); //skip the equal sign...
- if (NS_OK==result) {
+ if (NS_OK == result) {
+ // Skip ahead until you find an equal sign or a '>'...
+ result = aScanner.Peek(aChar);
+ if (NS_OK == result) {
+ if (kEqual == aChar) {
+ result = aScanner.GetChar(aChar); // Skip the equal sign...
+ if (NS_OK == result) {
if (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE) {
PRBool haveCR;
result = aScanner.ReadWhitespace(mTextValue, mNewlineCount,
haveCR);
- }
- else {
+ } else {
result = aScanner.SkipWhitespace(mNewlineCount);
}
- if (NS_OK==result) {
- result=aScanner.Peek(aChar); //and grab the next char.
- if (NS_OK==result) {
- if ((kQuote==aChar) || (kApostrophe==aChar)) {
+ if (NS_OK == result) {
+ result = aScanner.Peek(aChar); // And grab the next char.
+ if (NS_OK == result) {
+ if (kQuote == aChar || kApostrophe == aChar) {
aScanner.GetChar(aChar);
if (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE) {
mTextValue.writable().Append(aChar);
}
-
- result=ConsumeQuotedString(aChar,mTextValue,mNewlineCount,
- aScanner,aFlag);
- if (NS_SUCCEEDED(result) && (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
+
+ result = ConsumeQuotedString(aChar, mTextValue,
+ mNewlineCount, aScanner,
+ aFlag);
+ if (NS_SUCCEEDED(result) &&
+ (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
mTextValue.writable().Append(aChar);
- } else if (result == NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL) {
+ } else if (result ==
+ NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL) {
result = NS_OK;
mInError = PR_TRUE;
}
- // According to spec. we ( who? ) should ignore linefeeds. But look,
- // even the carriage return was getting stripped ( wonder why! ) -
- // Ref. to bug 15204. Okay, so the spec. told us to ignore linefeeds,
- // bug then what about bug 47535 ? Should we preserve everything then?
- // Well, let's make it so! Commenting out the next two lines..
- /*if(!aRetain)
- mTextValue.StripChars("\r\n"); //per the HTML spec, ignore linefeeds...
- */
- }
- else if (kGreaterThan==aChar){
- mHasEqualWithoutValue=PR_TRUE;
- mInError=PR_TRUE;
- }
- else {
+ // According to spec. we ( who? ) should ignore linefeeds.
+ // But look, even the carriage return was getting stripped
+ // ( wonder why! ) - Ref. to bug 15204. Okay, so the
+ // spec. told us to ignore linefeeds, bug then what about
+ // bug 47535 ? Should we preserve everything then? Well,
+ // let's make it so!
+ } else if (kGreaterThan == aChar) {
+ mHasEqualWithoutValue = PR_TRUE;
+ mInError = PR_TRUE;
+ } else {
static const nsReadEndCondition
theAttributeTerminator(kAttributeTerminalChars);
- result=ConsumeUntil(mTextValue,
- mNewlineCount,
- aScanner,
- theAttributeTerminator,
- PR_FALSE,
- PR_TRUE,
- aFlag);
- }
- }//if
- if (NS_OK==result) {
+ result =
+ ConsumeUntil(mTextValue,
+ mNewlineCount,
+ aScanner,
+ theAttributeTerminator,
+ PR_FALSE,
+ PR_TRUE,
+ aFlag);
+ }
+ }
+ if (NS_OK == result) {
if (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE) {
PRBool haveCR;
result = aScanner.ReadWhitespace(mTextValue, mNewlineCount,
haveCR);
- }
- else {
+ } else {
result = aScanner.SkipWhitespace(mNewlineCount);
}
}
- }//if
- else {
- //We saw an equal sign but ran out of room looking for a value.
- mHasEqualWithoutValue=PR_TRUE;
- mInError=PR_TRUE;
+ } else {
+ // We saw an equal sign but ran out of room looking for a value.
+ mHasEqualWithoutValue = PR_TRUE;
+ mInError = PR_TRUE;
}
- }//if
- }//if
- else {
- //This is where we have to handle fairly busted content.
- //If you're here, it means we saw an attribute name, but couldn't find
- //the following equal sign. REALLY ugly.
- //My best guess is to grab the next non-ws char. We know it's not '=',
- //so let's see what it is. If it's a '"', then assume we're reading
- //from the middle of the value. Try stripping the quote and continuing...
- //Note that this code also strips forward slashes to handle cases
- //like
+ }
+ } else {
+ // This is where we have to handle fairly busted content.
+ // If you're here, it means we saw an attribute name, but couldn't
+ // find the following equal sign. REALLY ugly.
+ // My best guess is to grab the next non-ws char. We know it's not
+ // '=', so let's see what it is. If it's a '"', then assume we're
+ // reading from the middle of the value. Try stripping the quote
+ // and continuing... Note that this code also strips forward
+ // slashes to handle cases like
if (kQuote == aChar || kApostrophe == aChar ||
kForwardSlash == aChar) {
// In XML, a trailing slash isn't an error.
@@ -2012,40 +1870,40 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner, PRInt32
result = aScanner.SkipWhitespace(mNewlineCount);
}
} else {
- //We want to collect whitespace here so that following
- //attributes can have the right line number (and for
- //parity with the non-view-source code above).
- result = ConsumeInvalidAttribute(aScanner, aChar, wsend, mNewlineCount);
+ // We want to collect whitespace here so that following
+ // attributes can have the right line number (and for
+ // parity with the non-view-source code above).
+ result = ConsumeInvalidAttribute(aScanner, aChar,
+ wsend, mNewlineCount);
aScanner.BindSubstring(mTextKey, wsstart, wsend);
aScanner.SetPosition(wsend);
- }
+ }
}
}
- }//if
- } //if
- }//if (consume optional value)
+ }
+ }
+ }
- if (NS_OK==result) {
- if (mTextValue.str().Length() == 0 && mTextKey.Length() == 0 &&
+ if (NS_OK == result) {
+ if (mTextValue.str().Length() == 0 && mTextKey.Length() == 0 &&
mNewlineCount == 0 && !mHasEqualWithoutValue) {
- //This attribute contains no useful information for us, so there is no
- //use in keeping it around. Attributes that are otherwise empty, but
- //have newlines in them are passed on the the DTD so it can get line
- //numbering right.
+ // This attribute contains no useful information for us, so there is no
+ // use in keeping it around. Attributes that are otherwise empty, but
+ // have newlines in them are passed on the the DTD so it can get line
+ // numbering right.
return NS_ERROR_HTMLPARSER_BADATTRIBUTE;
}
}
- }//if
+ }
if (kEOF == result && !aScanner.IsIncremental()) {
- // This is our run-of-the mill "don't lose content at the end of a
+ // This is our run-of-the mill "don't lose content at the end of a
// document" with a slight twist: we don't want to bother returning an
// empty attribute key, even if this is the end of the document.
if (mTextKey.Length() == 0) {
result = NS_ERROR_HTMLPARSER_BADATTRIBUTE;
- }
- else {
+ } else {
result = NS_OK;
}
}
@@ -2053,61 +1911,47 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner, PRInt32
return result;
}
-void CAttributeToken::SetKey(const nsAString& aKey)
+void
+CAttributeToken::SetKey(const nsAString& aKey)
{
mTextKey.Rebind(aKey);
}
-void CAttributeToken::BindKey(nsScanner* aScanner,
- nsScannerIterator& aStart,
- nsScannerIterator& aEnd)
+void
+CAttributeToken::BindKey(nsScanner* aScanner,
+ nsScannerIterator& aStart,
+ nsScannerIterator& aEnd)
{
aScanner->BindSubstring(mTextKey, aStart, aEnd);
}
-/*
- * default constructor
- *
- * @update gess 3/25/98
- * @param aName -- string to init token name with
- * @return
- */
-CWhitespaceToken::CWhitespaceToken() : CHTMLToken(eHTMLTag_whitespace) {
+CWhitespaceToken::CWhitespaceToken()
+ : CHTMLToken(eHTMLTag_whitespace)
+{
}
-
-/*
- * default constructor
- *
- * @update gess 3/25/98
- * @param aName -- string value to init token name with
- * @return
- */
-CWhitespaceToken::CWhitespaceToken(const nsAString& aName) : CHTMLToken(eHTMLTag_whitespace) {
+CWhitespaceToken::CWhitespaceToken(const nsAString& aName)
+ : CHTMLToken(eHTMLTag_whitespace)
+{
mTextValue.writable().Assign(aName);
}
-/*
- *
- *
- * @update gess 3/25/98
- * @param
- * @return
- */
-PRInt32 CWhitespaceToken::GetTokenType(void) {
+PRInt32 CWhitespaceToken::GetTokenType()
+{
return eToken_whitespace;
}
/*
- * This general purpose method is used when you want to
- * consume an aribrary sequence of whitespace.
- *
- * @update gess 3/25/98
+ * This general purpose method is used when you want to
+ * consume an aribrary sequence of whitespace.
+ *
* @param aChar -- last char consumed from stream
* @param aScanner -- controller of underlying input source
* @return error result
*/
-nsresult CWhitespaceToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag) {
+nsresult
+CWhitespaceToken::Consume(PRUnichar aChar, nsScanner& aScanner, PRInt32 aFlag)
+{
// If possible, we'd like to just be a dependent substring starting at
// |aChar|. The scanner has already been advanced, so we need to
// back it up to facilitate this.
@@ -2119,7 +1963,7 @@ nsresult CWhitespaceToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32
PRBool haveCR;
nsresult result = aScanner.ReadWhitespace(mTextValue, mNewlineCount, haveCR);
-
+
if (result == kEOF && !aScanner.IsIncremental()) {
// Oops, we ran off the end, make sure we don't lose the trailing
// whitespace!
@@ -2132,103 +1976,85 @@ nsresult CWhitespaceToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32
return result;
}
-const nsSubstring& CWhitespaceToken::GetStringValue(void)
+const nsSubstring&
+CWhitespaceToken::GetStringValue()
{
return mTextValue.str();
}
-/*
- * default constructor
- *
- * @update gess 3/25/98
- * @param aName -- string to init token name with
- * @return
- */
-CEntityToken::CEntityToken() : CHTMLToken(eHTMLTag_entity) {
+CEntityToken::CEntityToken()
+ : CHTMLToken(eHTMLTag_entity)
+{
}
-/*
- * default constructor
- *
- * @update gess 3/25/98
- * @param aName -- string value to init token name with
- * @return
- */
-CEntityToken::CEntityToken(const nsAString& aName) : CHTMLToken(eHTMLTag_entity) {
+CEntityToken::CEntityToken(const nsAString& aName)
+ : CHTMLToken(eHTMLTag_entity)
+{
mTextValue.Assign(aName);
-#ifdef VERBOSE_DEBUG
- if(!VerifyEntityTable()) {
- cout<<"Entity table is invalid!" << endl;
- }
-#endif
}
/*
* Consume the rest of the entity. We've already eaten the "&".
- *
- * @update gess 3/25/98
- * @param aChar -- last char consumed from stream
- * @param aScanner -- controller of underlying input source
- * @return error result
- */
-nsresult CEntityToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag) {
- nsresult result=ConsumeEntity(aChar,mTextValue,aScanner);
- return result;
-}
-
-/*
- *
- *
- * @update gess 3/25/98
- * @param
- * @return
- */
-PRInt32 CEntityToken::GetTokenType(void) {
- return eToken_entity;
-}
-
-/*
- * This general purpose method is used when you want to
- * consume an entity &xxxx;. Keep in mind that entities
- * are not reduced inline.
- *
- * @update gess 3/25/98
+ *
* @param aChar -- last char consumed from stream
* @param aScanner -- controller of underlying input source
* @return error result
*/
nsresult
+CEntityToken::Consume(PRUnichar aChar, nsScanner& aScanner, PRInt32 aFlag)
+{
+ nsresult result = ConsumeEntity(aChar, mTextValue, aScanner);
+ return result;
+}
+
+PRInt32
+CEntityToken::GetTokenType()
+{
+ return eToken_entity;
+}
+
+/*
+ * This general purpose method is used when you want to
+ * consume an entity &xxxx;. Keep in mind that entities
+ * are not reduced inline.
+ *
+ * @param aChar -- last char consumed from stream
+ * @param aScanner -- controller of underlying input source
+ * @return error result
+ */
+nsresult
CEntityToken::ConsumeEntity(PRUnichar aChar,
nsString& aString,
- nsScanner& aScanner) {
- nsresult result=NS_OK;
- if(kLeftBrace==aChar) {
- //you're consuming a script entity...
+ nsScanner& aScanner)
+{
+ nsresult result = NS_OK;
+ if (kLeftBrace == aChar) {
+ // You're consuming a script entity...
aScanner.GetChar(aChar); // Consume &
PRInt32 rightBraceCount = 0;
PRInt32 leftBraceCount = 0;
do {
- result=aScanner.GetChar(aChar);
-
+ result = aScanner.GetChar(aChar);
+
if (NS_FAILED(result)) {
return result;
}
aString.Append(aChar);
- if(aChar==kRightBrace)
+ if (aChar == kRightBrace) {
++rightBraceCount;
- else if(aChar==kLeftBrace)
+ } else if (aChar == kLeftBrace) {
++leftBraceCount;
- } while(leftBraceCount!=rightBraceCount);
- } //if
- else {
- PRUnichar theChar=0;
- if (kHashsign==aChar) {
- result = aScanner.Peek(theChar,2);
-
+ }
+ } while (leftBraceCount != rightBraceCount);
+ } else {
+ PRUnichar theChar = 0;
+ if (kHashsign == aChar) {
+ result = aScanner.Peek(theChar, 2);
+
if (NS_FAILED(result)) {
if (kEOF == result && !aScanner.IsIncremental()) {
// If this is the last buffer then we are certainly
@@ -2243,61 +2069,54 @@ CEntityToken::ConsumeEntity(PRUnichar aChar,
aScanner.GetChar(aChar); // Consume &
aScanner.GetChar(aChar); // Consume #
aString.Assign(aChar);
- result=aScanner.ReadNumber(aString,10);
- }
- else if (theChar == 'x' || theChar == 'X') {
+ result = aScanner.ReadNumber(aString, 10);
+ } else if (theChar == 'x' || theChar == 'X') {
aScanner.GetChar(aChar); // Consume &
aScanner.GetChar(aChar); // Consume #
aScanner.GetChar(theChar); // Consume x
aString.Assign(aChar);
- aString.Append(theChar);
- result=aScanner.ReadNumber(aString,16);
+ aString.Append(theChar);
+ result = aScanner.ReadNumber(aString, 16);
+ } else {
+ return NS_HTMLTOKENS_NOT_AN_ENTITY;
}
- else {
- return NS_HTMLTOKENS_NOT_AN_ENTITY;
- }
- }
- else {
- result = aScanner.Peek(theChar,1);
-
+ } else {
+ result = aScanner.Peek(theChar, 1);
+
if (NS_FAILED(result)) {
return result;
}
- if(nsCRT::IsAsciiAlpha(theChar) ||
+ if (nsCRT::IsAsciiAlpha(theChar) ||
theChar == '_' ||
theChar == ':') {
aScanner.GetChar(aChar); // Consume &
- result=aScanner.ReadEntityIdentifier(aString);
- }
- else {
+ result = aScanner.ReadEntityIdentifier(aString);
+ } else {
return NS_HTMLTOKENS_NOT_AN_ENTITY;
}
}
}
-
+
if (NS_FAILED(result)) {
return result;
}
-
- result=aScanner.Peek(aChar);
-
+
+ result = aScanner.Peek(aChar);
+
if (NS_FAILED(result)) {
return result;
}
if (aChar == kSemicolon) {
- // consume semicolon that stopped the scan
+ // Consume semicolon that stopped the scan
aString.Append(aChar);
- result=aScanner.GetChar(aChar);
+ result = aScanner.GetChar(aChar);
}
-
+
return result;
}
-#define PA_REMAP_128_TO_160_ILLEGAL_NCR 1
-
-#ifdef PA_REMAP_128_TO_160_ILLEGAL_NCR
/**
* Map some illegal but commonly used numeric entities into their
* appropriate unicode value.
@@ -2338,94 +2157,78 @@ static const PRUint16 PA_HackTable[] = {
0x017E, /* LATIN SMALL LETTER Z WITH CARON */
0x0178 /* LATIN CAPITAL LETTER Y WITH DIAERESIS */
};
-#endif /* PA_REMAP_128_TO_160_ILLEGAL_NCR */
-static void AppendNCR(nsSubstring& aString, PRInt32 aNCRValue)
+static void
+AppendNCR(nsSubstring& aString, PRInt32 aNCRValue)
{
-#ifdef PA_REMAP_128_TO_160_ILLEGAL_NCR
- /* for some illegal, but popular usage */
- if ((aNCRValue >= 0x0080) && (aNCRValue <= 0x009f)) {
+ /* For some illegal, but popular usage */
+ if (aNCRValue >= 0x0080 && aNCRValue <= 0x009f) {
aNCRValue = PA_HackTable[aNCRValue - 0x0080];
}
-#endif
AppendUCS4ToUTF16(ENSURE_VALID_CHAR(aNCRValue), aString);
}
/*
- * This method converts this entity into its underlying
- * unicode equivalent.
- *
- * @update gess 3/25/98
+ * This method converts this entity into its underlying
+ * unicode equivalent.
+ *
* @param aString will hold the resulting string value
* @return numeric (unichar) value
*/
-PRInt32 CEntityToken::TranslateToUnicodeStr(nsString& aString) {
- PRInt32 value=0;
+PRInt32
+CEntityToken::TranslateToUnicodeStr(nsString& aString)
+{
+ PRInt32 value = 0;
- if(mTextValue.Length()>1) {
- PRUnichar theChar0=mTextValue.CharAt(0);
+ if (mTextValue.Length() > 1) {
+ PRUnichar theChar0 = mTextValue.CharAt(0);
- if(kHashsign==theChar0) {
- PRInt32 err=0;
-
- value=mTextValue.ToInteger(&err,kAutoDetect);
+ if (kHashsign == theChar0) {
+ PRInt32 err = 0;
- if(0==err) {
+ value = mTextValue.ToInteger(&err, kAutoDetect);
+
+ if (0 == err) {
AppendNCR(aString, value);
}
- }
- else{
+ } else {
value = nsHTMLEntities::EntityToUnicode(mTextValue);
- if(-1= eHTMLTag_userdefined)
+ if (aTag >= eHTMLTag_userdefined) {
return sUserdefined;
+ }
return 0;
}
-/**
- *
- *
- * @update gess 9/23/98
- * @param
- * @return
- */
-CInstructionToken::CInstructionToken() : CHTMLToken(eHTMLTag_instruction) {
+CInstructionToken::CInstructionToken()
+ : CHTMLToken(eHTMLTag_instruction)
+{
}
-/**
- *
- *
- * @update gess 9/23/98
- * @param
- * @return
- */
-CInstructionToken::CInstructionToken(const nsAString& aString) : CHTMLToken(eHTMLTag_unknown) {
+CInstructionToken::CInstructionToken(const nsAString& aString)
+ : CHTMLToken(eHTMLTag_unknown)
+{
mTextValue.Assign(aString);
}
-/**
- *
- *
- * @update gess 9/23/98
- * @param
- * @return
- */
-nsresult CInstructionToken::Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32 aFlag){
+nsresult
+CInstructionToken::Consume(PRUnichar aChar, nsScanner& aScanner, PRInt32 aFlag)
+{
mTextValue.AssignLiteral("");
- nsresult result=NS_OK;
- PRBool done=PR_FALSE;
-
- while (NS_OK==result && !done) {
- //Note, this call does *not* consume the >.
- result=aScanner.ReadUntil(mTextValue,kGreaterThan,PR_FALSE);
+ nsresult result = NS_OK;
+ PRBool done = PR_FALSE;
+
+ while (NS_OK == result && !done) {
+ // Note, this call does *not* consume the >.
+ result = aScanner.ReadUntil(mTextValue, kGreaterThan, PR_FALSE);
if (NS_SUCCEEDED(result)) {
- //In HTML, PIs end with a '>', in XML, they end with a '?>'. Cover both
- //cases here.
- if (!(aFlag & NS_IPARSER_FLAG_XML) || kQuestionMark==mTextValue.Last()) {
- //This really is the end of the PI.
- done=PR_TRUE;
+ // In HTML, PIs end with a '>', in XML, they end with a '?>'. Cover both
+ // cases here.
+ if (!(aFlag & NS_IPARSER_FLAG_XML) ||
+ kQuestionMark == mTextValue.Last()) {
+ // This really is the end of the PI.
+ done = PR_TRUE;
}
- //Need to append this character no matter what.
+ // Need to append this character no matter what.
aScanner.GetChar(aChar);
mTextValue.Append(aChar);
}
}
- if (kEOF==result && !aScanner.IsIncremental()) {
- //Hide the EOF result because there is no more text coming.
- mInError=PR_TRUE;
- result=NS_OK;
+ if (kEOF == result && !aScanner.IsIncremental()) {
+ // Hide the EOF result because there is no more text coming.
+ mInError = PR_TRUE;
+ result = NS_OK;
}
return result;
}
-/**
- *
- *
- * @update gess 9/23/98
- * @param
- * @return
- */
-PRInt32 CInstructionToken::GetTokenType(void){
+PRInt32
+CInstructionToken::GetTokenType()
+{
return eToken_instruction;
}
-const nsSubstring& CInstructionToken::GetStringValue(void)
+const nsSubstring&
+CInstructionToken::GetStringValue()
{
return mTextValue;
}
@@ -2517,76 +2303,80 @@ const nsSubstring& CInstructionToken::GetStringValue(void)
// Doctype decl token
CDoctypeDeclToken::CDoctypeDeclToken(eHTMLTags aTag)
- : CHTMLToken(aTag) {
+ : CHTMLToken(aTag)
+{
}
-CDoctypeDeclToken::CDoctypeDeclToken(const nsAString& aString,eHTMLTags aTag)
- : CHTMLToken(aTag), mTextValue(aString) {
+CDoctypeDeclToken::CDoctypeDeclToken(const nsAString& aString, eHTMLTags aTag)
+ : CHTMLToken(aTag), mTextValue(aString)
+{
}
/**
* This method consumes a doctype element.
- * Note: I'm rewriting this method to seek to the first <, since quotes can really screw us up.
- *
- * @update gess 9/23/98
- * @param
- * @return
+ * Note: I'm rewriting this method to seek to the first <, since quotes can
+ * really screw us up.
+ * XXX Maybe this should do better in XML or strict mode?
*/
-nsresult CDoctypeDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag) {
-
- static const PRUnichar terminalChars[] =
+nsresult
+CDoctypeDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner, PRInt32 aFlag)
+{
+ static const PRUnichar terminalChars[] =
{ PRUnichar('>'), PRUnichar('<'),
- PRUnichar(0)
+ PRUnichar(0)
};
static const nsReadEndCondition theEndCondition(terminalChars);
nsScannerIterator start, end;
-
+
aScanner.CurrentPosition(start);
aScanner.EndReading(end);
- nsresult result=aScanner.ReadUntil(start, end, theEndCondition, PR_FALSE);
+ nsresult result = aScanner.ReadUntil(start, end, theEndCondition, PR_FALSE);
if (NS_SUCCEEDED(result)) {
PRUnichar ch;
aScanner.Peek(ch);
if (ch == kGreaterThan) {
- // Include '>' but not '<' since '<'
+ // Include '>' but not '<' since '<'
// could belong to another tag.
aScanner.GetChar(ch);
- end.advance(1);
+ end.advance(1);
} else {
- NS_ASSERTION(kLessThan == ch,
+ NS_ASSERTION(kLessThan == ch,
"Make sure this doctype decl. is really in error.");
mInError = PR_TRUE;
}
- }
- else if (!aScanner.IsIncremental()) {
+ } else if (!aScanner.IsIncremental()) {
// We have reached the document end but haven't
// found either a '<' or a '>'. Therefore use
// whatever we have.
mInError = PR_TRUE;
- result = NS_OK;
+ result = NS_OK;
}
-
+
if (NS_SUCCEEDED(result)) {
start.advance(-2); // Make sure to consume