Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends
CCommentToken Class Reference

This declares comment tokens. More...

#include <nsHTMLTokens.h>

Inheritance diagram for CCommentToken:
Inheritance graph
[legend]
Collaboration diagram for CCommentToken:
Collaboration graph
[legend]

List of all members.

Public Types

enum  eTokenOrigin { eSource, eResidualStyle }

Public Member Functions

 CCommentToken ()
 CCommentToken (const nsAString &aString)
virtual nsresult Consume (PRUnichar aChar, nsScanner &aScanner, PRInt32 aMode)
 Causes token to consume data from given scanner.
virtual PRInt32 GetTokenType (void)
 Getter which retrieves type of token gess5/11/98.
virtual const nsSubstringGetStringValue (void)
 Retrieve string value of the token gess5/11/98.
virtual void AppendSourceTo (nsAString &anOutputString)
 harishd 03/23/00
nsresult ConsumeStrictComment (nsScanner &aScanner)
nsresult ConsumeQuirksComment (nsScanner &aScanner)
virtual eContainerInfo GetContainerInfo (void) const
virtual void SetContainerInfo (eContainerInfo aInfo)
void AddRef ()
 Make a note on number of times you have been referenced harishd 08/02/00.
void Release (nsFixedSizeAllocator &aArenaPool)
 Free yourself if no one is holding you.
virtual void GetSource (nsString &anOutputString)
 Get string of full contents, suitable for debug dump.
void SetTypeID (PRInt32 aValue)
 Sets the ordinal value of this token (not currently used) gess5/11/98.
virtual PRInt32 GetTypeID (void)
 Getter which retrieves the current ordinal value for this token gess5/11/98.
virtual PRInt16 GetAttributeCount (void)
 Getter which retrieves the current attribute count for this token gess5/11/98.
virtual PRBool IsWellFormed (void) const
 For tokens who care, this can tell us whether the token is well formed or not.
virtual PRBool IsEmpty (void)
virtual void SetEmpty (PRBool aValue)
 If aValue is TRUE then the token represents a short-hand tag.
PRInt32 GetNewlineCount ()
void SetNewlineCount (PRInt32 aCount)
PRInt32 GetLineNumber ()
void SetLineNumber (PRInt32 aLineNumber)
void SetInError (PRBool aInError)
PRBool IsInError ()
void SetAttributeCount (PRInt16 aValue)
virtual void SelfTest (void)
 perform self test.

Static Public Member Functions

static void Destroy (CToken *aToken, nsFixedSizeAllocator &aArenaPool)
 Destroy a token.
static int GetTokenCount ()

Protected Member Functions

virtual size_t SizeOf () const =0
 Returns the size of the token object.

Static Protected Member Functions

static voidoperator new (size_t aSize, nsFixedSizeAllocator &anArena) CPP_THROW_NEW
 harishd 08/01/00
static void operator delete (void *, size_t)
 Hide operator delete; clients should use Destroy() instead.

Protected Attributes

nsScannerSubstring mComment
nsScannerSubstring mCommentDecl
PRInt32 mTypeID
PRInt32 mUseCount
PRInt32 mNewlineCount
PRUint32 mLineNumber: 31
PRUint32 mInError: 1
PRInt16 mAttrCount

Friends

class nsTokenAllocator

Detailed Description

This declares comment tokens.

Comments are usually thought of as tokens, but we treat them that way here so that the parser can have a consistent view of all tokens.

gess 3/25/98

Definition at line 202 of file nsHTMLTokens.h.


Member Enumeration Documentation

enum CToken::eTokenOrigin [inherited]
Enumerator:
eSource 
eResidualStyle 

Definition at line 109 of file nsToken.h.


Constructor & Destructor Documentation

Definition at line 1284 of file nsHTMLTokens.cpp.

                             : CHTMLToken(eHTMLTag_comment) {
}
CCommentToken::CCommentToken ( const nsAString &  aString)

Definition at line 1295 of file nsHTMLTokens.cpp.

                                                   : CHTMLToken(eHTMLTag_comment) {
  mComment.Rebind(aName);
}

Here is the call graph for this function:


Member Function Documentation

void CToken::AddRef ( void  ) [inline, inherited]

Make a note on number of times you have been referenced harishd 08/02/00.

Definition at line 154 of file nsToken.h.

{ ++mUseCount; }
void CCommentToken::AppendSourceTo ( nsAString &  anOutputString) [virtual]

harishd 03/23/00

harishd 3/23/00

Returns:
reference to string containing string value

Reimplemented from CToken.

Definition at line 1299 of file nsHTMLTokens.cpp.

                                                           {
  AppendUnicodeTo(mCommentDecl, anOutputString);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult CCommentToken::Consume ( PRUnichar  aChar,
nsScanner aScanner,
PRInt32  aMode 
) [virtual]

Causes token to consume data from given scanner.

Virtual method used to tell this toke to consume his valid chars.

Note that behavior varies wildly between CToken subclasses. gess5/11/98

Parameters:
aChar-- most recent char consumed
aScanner-- input source where token should get data
Returns:
error code (0 means ok)

gess 3/25/98

Parameters:
aChar-- first char in sequence
aScanner-- object to retrieve data from
Returns:
int error code

Reimplemented from CToken.

Definition at line 1556 of file nsHTMLTokens.cpp.

                                                                                  {
  nsresult result=PR_TRUE;
  
  if (aFlag & NS_IPARSER_FLAG_STRICT_MODE) {
    //Enabling strict comment parsing for Bug 53011 and  2749 contradicts!!!!
    result = ConsumeStrictComment(aScanner);
  }
  else {
    result = ConsumeQuirksComment(aScanner);
  }

  if (NS_SUCCEEDED(result)) {
    mNewlineCount = !(aFlag & NS_IPARSER_FLAG_VIEW_SOURCE) ? mCommentDecl.CountChar(kNewLine) : -1;
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1404 of file nsHTMLTokens.cpp.

{
  // <![-[-]] ... [[-]-|--!]>
  /*********************************************************
    NOTE: This algorithm does a fine job of handling comments
          commonly used, but it doesn't really consume them
          per spec (But then, neither does IE or Nav).
   *********************************************************/
  nsScannerIterator end, current;
  aScanner.EndReading(end);
  aScanner.CurrentPosition(current);
  nsScannerIterator beginData = current, 
                    beginLastMinus = end,
                    bestAltCommentEnd = end,
                    lt = current;
  lt.advance(-2); // <!

  // When we get here, we have always already consumed <!
  // Skip over possible leading minuses
  if (current != end && *current == kMinus) {
    beginLastMinus = current;
    ++current;
    ++beginData;
    if (current != end && *current == kMinus) { // <!--
      beginLastMinus = current;
      ++current;
      ++beginData;
      // Long form comment

      nsScannerIterator currentEnd = end, gt = end;
      
      // Find the end of the comment
      while (FindCharInReadable(kGreaterThan, current, currentEnd)) {
        gt = current;
        if (bestAltCommentEnd == end) {
          bestAltCommentEnd = gt;
        }
        --current;
        PRBool goodComment = PR_FALSE;
        if (current != beginLastMinus && *current == kMinus) { // ->
          --current;
          if (current != beginLastMinus && *current == kMinus) { // -->
            goodComment = PR_TRUE;
            --current;
          }
        } else if (current != beginLastMinus && *current == '!') {
          --current;
          if (current != beginLastMinus && *current == kMinus) {
            --current;
            if (current != beginLastMinus && *current == kMinus) { // --!>
              --current;
              goodComment = PR_TRUE;
            }
          }
        } else if (current == beginLastMinus) {
          goodComment = PR_TRUE;
        }
    
        if (goodComment) {
          // done
          aScanner.BindSubstring(mComment, beginData, ++current);
          aScanner.BindSubstring(mCommentDecl, lt, ++gt);
          aScanner.SetPosition(gt);
          return NS_OK;
        } else {
          // try again starting after the last '>'
          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
        // case the return value here will cause us to unwind,
        // wait for more content, and try again.
        // XXX For performance reasons we should cache where we were, and
        //     continue from there for next call
        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.
      gt = bestAltCommentEnd;
      aScanner.BindSubstring(mComment, beginData, gt);
      if (gt != end) {
        ++gt;
      }
      aScanner.BindSubstring(mCommentDecl, lt, gt);
      aScanner.SetPosition(gt);
      return NS_OK;
    }
  }
  
  // This could be short form of comment
  // Find the end of the comment
  current = beginData;
  if (FindCharInReadable(kGreaterThan, current, end)) {
    nsScannerIterator gt = current;
    if (current != beginData) {
      --current;
      if (current != beginData && *current == kMinus) { // ->
        --current;
        if (current != beginData && *current == kMinus) { // -->
          --current;
        }
      } else if (current != beginData && *current == '!') { // !>
        --current;
        if (current != beginData && *current == kMinus) { // -!>
          --current;
          if (current != beginData && *current == kMinus) { // --!>
            --current;
          }
        }
      }
    }

    if (current != gt) {
      aScanner.BindSubstring(mComment, beginData, ++current);
    }
    else {
      // Bind mComment to an empty string (note that if current == gt,
      // then current == beginData). We reach this for <!>
      aScanner.BindSubstring(mComment, beginData, current);
    }
    aScanner.BindSubstring(mCommentDecl, lt, ++gt);
    aScanner.SetPosition(gt);
    return NS_OK;
  }

  if (!aScanner.IsIncremental()) {
    // This isn't a comment at all, go back to the < and consume as text.
    aScanner.SetPosition(lt, PR_FALSE, PR_TRUE);
    return kNotAComment;
  }

  // Wait for more data...
  return kEOF;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1327 of file nsHTMLTokens.cpp.

{
  // <!--[... -- ... -- ...]*-->
  /*********************************************************
    NOTE: This algorithm does a fine job of handling comments
          when they're formatted per spec, but if they're not
          we don't handle them well.
   *********************************************************/
  nsScannerIterator end, current, gt, lt;
  aScanner.EndReading(end);
  aScanner.CurrentPosition(current);

  nsScannerIterator beginData = end;

  lt = current;
  lt.advance(-2); // <!

  // Regular comment must start with <!--
  if (current != end && *current == kMinus &&
      ++current != end && *current == kMinus &&
      ++current != end) {
    nsScannerIterator currentEnd = end;
    PRBool balancedComment = PR_FALSE;
    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);
        // Note: it's ok if beginData == current, (we'll copy an empty string)
        // and we need to bind mComment anyway.
        aScanner.BindSubstring(mComment, beginData, current);
        aScanner.BindSubstring(mCommentDecl, lt, ++gt);
        aScanner.SetPosition(gt);
        return NS_OK;
      } else {
        // Continue after the last '--'
        currentEnd = end;
      }
    }
  }

  // If beginData == end, we did not find opening '--'
  if (beginData == end) {
    // This might have been empty comment: <!>
    // Or it could have been something completely bogus like: <!This is foobar>
    // Handle both cases below
    aScanner.CurrentPosition(current);
    beginData = current;
    if (FindCharInReadable('>', current, end)) {
      aScanner.BindSubstring(mComment, beginData, current); 
      aScanner.BindSubstring(mCommentDecl, lt, ++current);
      aScanner.SetPosition(current);
      return NS_OK;
    }
  }

  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
    // case the return value here will cause us to unwind,
    // wait for more content, and try again.
    // XXX For performance reasons we should cache where we were, and
    //     continue from there for next call
    return kEOF;
  }

  // There was no terminating string, parse this comment as text.
  aScanner.SetPosition(lt, PR_FALSE, PR_TRUE);
  return kNotAComment;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void CToken::Destroy ( CToken aToken,
nsFixedSizeAllocator &  aArenaPool 
) [inline, static, inherited]

Destroy a token.

Definition at line 143 of file nsToken.h.

    {
      size_t sz = aToken->SizeOf();
      aToken->~CToken();
      aArenaPool.Free(aToken, sz);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt16 CToken::GetAttributeCount ( void  ) [virtual, inherited]

Getter which retrieves the current attribute count for this token gess5/11/98.

Retrieves copy of attr count for this token.

Returns:
current attribute count

gess 3/25/98

Returns:
int containing attribute count

Definition at line 151 of file nsToken.cpp.

                                      {
  return mAttrCount;
}

Here is the caller graph for this function:

virtual eContainerInfo CHTMLToken::GetContainerInfo ( void  ) const [inline, virtual, inherited]

Reimplemented in CStartToken.

Definition at line 115 of file nsHTMLTokens.h.

{return eFormUnknown;}

Here is the caller graph for this function:

PRInt32 CToken::GetLineNumber ( void  ) [inline, inherited]

Definition at line 257 of file nsToken.h.

    { 
      return mLineNumber;
    }

Here is the caller graph for this function:

PRInt32 CToken::GetNewlineCount ( ) [inline, inherited]

Definition at line 247 of file nsToken.h.

    { 
      return mNewlineCount; 
    }

Here is the caller graph for this function:

void CToken::GetSource ( nsString anOutputString) [virtual, inherited]

Get string of full contents, suitable for debug dump.

It should look exactly like the input source. gess5/11/98

Returns:
reference to string containing string value

Reimplemented in CAttributeToken, CEntityToken, CEndToken, and CStartToken.

Definition at line 122 of file nsToken.cpp.

                                               {
  anOutputString.Assign(GetStringValue());
}

Here is the call graph for this function:

Here is the caller graph for this function:

Retrieve string value of the token gess5/11/98.

Returns:
reference to string containing string value

Implements CToken.

Definition at line 1574 of file nsHTMLTokens.cpp.

{
  return mComment.AsString();
}

Here is the call graph for this function:

int CToken::GetTokenCount ( ) [static, inherited]

Definition at line 49 of file nsToken.cpp.

Getter which retrieves type of token gess5/11/98.

Retrieve type of token.

Returns:
int containing token type

This class returns -1, but subclasses return something more meaningful.

gess 3/25/98

Returns:
int value containing token type.

Reimplemented from CToken.

Definition at line 1586 of file nsHTMLTokens.cpp.

                                        {
  return eToken_comment;
}
PRInt32 CToken::GetTypeID ( void  ) [virtual, inherited]

Getter which retrieves the current ordinal value for this token gess5/11/98.

Retrieves copy of internal ordinal value.

Returns:
current ordinal value

This method is deprecated, and will soon be going away.

gess 3/25/98

Returns:
int containing ordinal value

Reimplemented in CEndToken, and CStartToken.

Definition at line 141 of file nsToken.cpp.

                              {
  return mTypeID;
}

Here is the caller graph for this function:

virtual PRBool CToken::IsEmpty ( void  ) [inline, virtual, inherited]

Reimplemented in CStartToken.

Definition at line 240 of file nsToken.h.

{ return PR_FALSE; }
PRBool CToken::IsInError ( ) [inline, inherited]

Definition at line 272 of file nsToken.h.

    {
      return mInError;
    }

Here is the caller graph for this function:

virtual PRBool CToken::IsWellFormed ( void  ) const [inline, virtual, inherited]

For tokens who care, this can tell us whether the token is well formed or not.

gess 8/30/00

Returns:
PR_FALSE; subclasses MUST override if they care.

Reimplemented in CStartToken.

Definition at line 238 of file nsToken.h.

{return PR_FALSE;}

Here is the caller graph for this function:

static void CToken::operator delete ( void ,
size_t   
) [inline, static, protected, inherited]

Hide operator delete; clients should use Destroy() instead.

Definition at line 131 of file nsToken.h.

{}
static void* CToken::operator new ( size_t  aSize,
nsFixedSizeAllocator &  anArena 
) [inline, static, protected, inherited]

harishd 08/01/00

Parameters:
aSize-
aArena- Allocate memory from this pool.

Definition at line 123 of file nsToken.h.

    {
      return anArena.Alloc(aSize);
    }
void CToken::Release ( nsFixedSizeAllocator &  aArenaPool) [inline, inherited]

Free yourself if no one is holding you.

harishd 08/02/00

Definition at line 160 of file nsToken.h.

                                                   {
      if(--mUseCount==0)
        Destroy(this, aArenaPool);
    }

Here is the call graph for this function:

void CToken::SelfTest ( void  ) [virtual, inherited]

perform self test.

gess 3/25/98

gess5/11/98

Definition at line 172 of file nsToken.cpp.

                          {
#ifdef _DEBUG
#endif
}
void CToken::SetAttributeCount ( PRInt16  aValue) [inline, inherited]

Definition at line 277 of file nsToken.h.

Here is the caller graph for this function:

virtual void CHTMLToken::SetContainerInfo ( eContainerInfo  aInfo) [inline, virtual, inherited]

Reimplemented in CStartToken.

Definition at line 116 of file nsHTMLTokens.h.

{ }

Here is the caller graph for this function:

virtual void CToken::SetEmpty ( PRBool  aValue) [inline, virtual, inherited]

If aValue is TRUE then the token represents a short-hand tag.

Reimplemented in CStartToken.

Definition at line 245 of file nsToken.h.

{ return ; }

Here is the call graph for this function:

Here is the caller graph for this function:

void CToken::SetInError ( PRBool  aInError) [inline, inherited]

Definition at line 267 of file nsToken.h.

    {
      mInError = aInError;
    }

Here is the caller graph for this function:

void CToken::SetLineNumber ( PRInt32  aLineNumber) [inline, inherited]

Definition at line 262 of file nsToken.h.

    { 
      mLineNumber = mLineNumber == 0 ? aLineNumber : mLineNumber;
    }
void CToken::SetNewlineCount ( PRInt32  aCount) [inline, inherited]

Definition at line 252 of file nsToken.h.

Here is the caller graph for this function:

void CToken::SetTypeID ( PRInt32  aValue) [inline, inherited]

Sets the ordinal value of this token (not currently used) gess5/11/98.

Parameters:
valueis the new ord value for this token

Definition at line 196 of file nsToken.h.

                                   {
      mTypeID = aValue;
    }

Here is the caller graph for this function:

virtual size_t CToken::SizeOf ( ) const [protected, pure virtual, inherited]

Returns the size of the token object.

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class nsTokenAllocator [friend, inherited]

Definition at line 115 of file nsToken.h.


Member Data Documentation

PRInt16 CToken::mAttrCount [protected, inherited]

Definition at line 300 of file nsToken.h.

Definition at line 217 of file nsHTMLTokens.h.

Definition at line 218 of file nsHTMLTokens.h.

PRUint32 CToken::mInError [protected, inherited]

Definition at line 299 of file nsToken.h.

PRUint32 CToken::mLineNumber [protected, inherited]

Definition at line 298 of file nsToken.h.

PRInt32 CToken::mNewlineCount [protected, inherited]

Definition at line 297 of file nsToken.h.

PRInt32 CToken::mTypeID [protected, inherited]

Definition at line 295 of file nsToken.h.

PRInt32 CToken::mUseCount [protected, inherited]

Definition at line 296 of file nsToken.h.


The documentation for this class was generated from the following files: