Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nsHTMLTokens.cpp File Reference
#include <ctype.h>
#include <time.h>
#include <stdio.h>
#include "nsScanner.h"
#include "nsToken.h"
#include "nsIAtom.h"
#include "nsHTMLTokens.h"
#include "prtypes.h"
#include "nsDebug.h"
#include "nsHTMLTags.h"
#include "nsHTMLEntities.h"
#include "nsCRT.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"

Go to the source code of this file.

Defines

#define PA_REMAP_128_TO_160_ILLEGAL_NCR   1
#define NOT_USED   0xfffd
 Map some illegal but commonly used numeric entities into their appropriate unicode value.

Functions

static void AppendNCR (nsSubstring &aString, PRInt32 aNCRValue)
static nsresult ConsumeEntity (nsScannerSharedSubstring &aString, nsScanner &aScanner, PRInt32 aFlag)
static nsresult ConsumeUntil (nsScannerSharedSubstring &aString, PRInt32 &aNewlineCount, nsScanner &aScanner, const nsReadEndCondition &aEndCondition, PRBool aAllowNewlines, PRInt32 aFlag)
static PRBool IsCommentEnd (const nsScannerIterator &aCurrent, const nsScannerIterator &aEnd, nsScannerIterator &aGt)
static nsresult ConsumeQuotedString (PRUnichar aChar, nsScannerSharedSubstring &aString, PRInt32 &aNewlineCount, nsScanner &aScanner, PRInt32 aFlag)
static nsresult ConsumeInvalidAttribute (nsScanner &aScanner, PRUnichar aChar, nsScannerIterator &aCurrent, PRInt32 &aNewlineCount)
const PRUnicharGetTagName (PRInt32 aTag)
 gess4/25/98

Variables

static const PRUnichar sUserdefined []
static const PRUnichar kAttributeTerminalChars []
static nsScannerSubstringgNewlineStr
static const PRUint16 PA_HackTable []

Define Documentation

#define NOT_USED   0xfffd

Map some illegal but commonly used numeric entities into their appropriate unicode value.

Definition at line 2320 of file nsHTMLTokens.cpp.

Definition at line 2313 of file nsHTMLTokens.cpp.


Function Documentation

static void AppendNCR ( nsSubstring aString,
PRInt32  aNCRValue 
) [static]

Definition at line 2358 of file nsHTMLTokens.cpp.

{
#ifdef PA_REMAP_128_TO_160_ILLEGAL_NCR
  /* for some illegal, but popular usage */
  if ((aNCRValue >= 0x0080) && (aNCRValue <= 0x009f)) {
    aNCRValue = PA_HackTable[aNCRValue - 0x0080];
  }
#endif

  AppendUCS4ToUTF16(ENSURE_VALID_CHAR(aNCRValue), aString);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult ConsumeEntity ( nsScannerSharedSubstring aString,
nsScanner aScanner,
PRInt32  aFlag 
) [static]

Definition at line 74 of file nsHTMLTokens.cpp.

{
  nsresult result=NS_OK;

  PRUnichar ch;
  result=aScanner.Peek(ch, 1);

  if (NS_SUCCEEDED(result)) {
    PRUnichar amp=0;
    PRInt32 theNCRValue=0;
    nsAutoString entity;

    if (nsCRT::IsAsciiAlpha(ch) && !(aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
      result=CEntityToken::ConsumeEntity(ch,entity,aScanner);
      if (NS_SUCCEEDED(result)) {
        theNCRValue = nsHTMLEntities::EntityToUnicode(entity);
        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 || (theNCRValue > 255 && theTermChar != ';')) {
          // Looks like we're not dealing with an entity
          writable.Append(kAmpersand);
          writable.Append(entity);
        }
        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);
      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 {
          PRInt32 err;
          theNCRValue=entity.ToInteger(&err,kAutoDetect);
          AppendNCR(writable, theNCRValue);
        }
      }
    }
    else {
      // What we thought as entity is not really an entity...
      aScanner.GetChar(amp);
      aString.writable().Append(amp);
    }//if
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult ConsumeInvalidAttribute ( nsScanner aScanner,
PRUnichar  aChar,
nsScannerIterator aCurrent,
PRInt32 aNewlineCount 
) [static]

Definition at line 1853 of file nsHTMLTokens.cpp.

                                                         {
  NS_ASSERTION(aChar == kApostrophe || aChar == kQuote || aChar == kForwardSlash,
               "aChar must be a quote or apostrophe");
  nsScannerIterator end, wsbeg;
  aScanner.EndReading(end);

  while (aCurrent != end && *aCurrent == aChar) {
    ++aCurrent;
  }

  aScanner.SetPosition(aCurrent);
  return aScanner.ReadWhitespace(wsbeg, aCurrent, aNewlineCount);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult ConsumeQuotedString ( PRUnichar  aChar,
nsScannerSharedSubstring aString,
PRInt32 aNewlineCount,
nsScanner aScanner,
PRInt32  aFlag 
) [static]

Definition at line 1785 of file nsHTMLTokens.cpp.

{
  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[] = { 
    PRUnichar(kQuote), PRUnichar('&'), PRUnichar(kCR),
    PRUnichar(kNewLine), PRUnichar(0) };
  static const PRUnichar theTerminalCharsApostrophe[] = { 
    PRUnichar(kApostrophe), PRUnichar('&'), PRUnichar(kCR),
    PRUnichar(kNewLine), PRUnichar(0) };
  static const nsReadEndCondition
    theTerminateConditionQuote(theTerminalCharsQuote);
  static const nsReadEndCondition
    theTerminateConditionApostrophe(theTerminalCharsApostrophe);

  // Assume Quote to init to something
  const nsReadEndCondition *terminateCondition = &theTerminateConditionQuote;
  if (aChar==kApostrophe)
    terminateCondition = &theTerminateConditionApostrophe;
  
  nsresult result=NS_OK;
  nsScannerIterator theOffset;
  aScanner.CurrentPosition(theOffset);

  result=ConsumeUntil(aString,aNewlineCount,aScanner,
                      *terminateCondition,PR_TRUE,aFlag);

  if(NS_SUCCEEDED(result)) {
    result = aScanner.GetChar(aChar); // aChar should be " or '
  }

  // Ref: Bug 35806
  // A back up measure when disaster strikes...
  // Ex <table> <tr d="><td>hello</td></tr></table>
  if(!aString.str().IsEmpty() && aString.str().Last()!=aChar &&
     !aScanner.IsIncremental() && result==kEOF) {
    static const nsReadEndCondition
      theAttributeTerminator(kAttributeTerminalChars);
    aString.writable().Truncate(origLen);
    aScanner.SetPosition(theOffset, PR_FALSE, PR_TRUE);
    result=ConsumeUntil(aString,aNewlineCount,aScanner,
                        theAttributeTerminator,PR_FALSE,aFlag);
    if (NS_SUCCEEDED(result) && (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
      // Remember that this string literal was unterminated.
      result = NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL;
    }
  }
  return result;
}

Here is the call graph for this function:

static nsresult ConsumeUntil ( nsScannerSharedSubstring aString,
PRInt32 aNewlineCount,
nsScanner aScanner,
const nsReadEndCondition aEndCondition,
PRBool  aAllowNewlines,
PRInt32  aFlag 
) [static]

Definition at line 152 of file nsHTMLTokens.cpp.

{
  nsresult result = NS_OK;
  PRBool   done = PR_FALSE;
  
  do {
    result = aScanner.ReadUntil(aString,aEndCondition,PR_FALSE);
    if(NS_SUCCEEDED(result)) {
      PRUnichar ch;
      aScanner.Peek(ch);
      if(ch == kAmpersand) {
        result = ConsumeEntity(aString,aScanner,aFlag);
      }
      else if(ch == kCR && aAllowNewlines) {
        aScanner.GetChar(ch);
        result = aScanner.Peek(ch);
        if (NS_SUCCEEDED(result)) {
          nsSubstring &writable = aString.writable();
          if(ch == kNewLine) {
            writable.AppendLiteral("\r\n");
            aScanner.GetChar(ch);
          }
          else {
            writable.Append(PRUnichar('\r'));
          }
          ++aNewlineCount;
        }
      }
      else if(ch == kNewLine && aAllowNewlines) {
        aScanner.GetChar(ch);
        aString.writable().Append(PRUnichar('\n'));
        ++aNewlineCount;
      }
      else {
        done = PR_TRUE;
      }
    }
  } while (NS_SUCCEEDED(result) && !done);

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gess4/25/98

Parameters:
@return

Definition at line 2443 of file nsHTMLTokens.cpp.

{
  const PRUnichar *result = nsHTMLTags::GetStringValue((nsHTMLTag) aTag);

  if (result) {
    return result;
  }

  if(aTag >= eHTMLTag_userdefined)
    return sUserdefined;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool IsCommentEnd ( const nsScannerIterator aCurrent,
const nsScannerIterator aEnd,
nsScannerIterator aGt 
) [static]

Definition at line 1303 of file nsHTMLTokens.cpp.

{
  nsScannerIterator current = aCurrent;
  PRInt32 dashes = 0;

  while ((current != aEnd) && (dashes != 2)) {
    if (*current == kGreaterThan) {
      aGt = current;
      return PR_TRUE;
    }
    if (*current == PRUnichar('-')) {
      ++dashes;
    } else {
      dashes = 0;
    }
    ++current;
  }

  return PR_FALSE;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 1612 of file nsHTMLTokens.cpp.

Initial value:
 {
  PRUnichar('&'), PRUnichar('\t'), PRUnichar('\n'),
  PRUnichar('\r'), PRUnichar(' '), PRUnichar('>'),
  PRUnichar(0) 
}

Definition at line 60 of file nsHTMLTokens.cpp.

Definition at line 2322 of file nsHTMLTokens.cpp.

Initial value:
 {'u', 's', 'e', 'r', 'd', 'e', 'f',
                                         'i', 'n', 'e', 'd', 0}

Definition at line 57 of file nsHTMLTokens.cpp.