PageRenderTime 161ms CodeModel.GetById 27ms app.highlight 122ms RepoModel.GetById 1ms app.codeStats 1ms

/parser/html/nsHtml5Tokenizer.cpp

http://github.com/zpao/v8monkey
C++ | 4091 lines | 3990 code | 73 blank | 28 comment | 608 complexity | 9b2ee1bd9b9849e3c5edb78ad7dcc78f MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/*
   2 * Copyright (c) 2005-2007 Henri Sivonen
   3 * Copyright (c) 2007-2010 Mozilla Foundation
   4 * Portions of comments Copyright 2004-2010 Apple Computer, Inc., Mozilla 
   5 * Foundation, and Opera Software ASA.
   6 *
   7 * Permission is hereby granted, free of charge, to any person obtaining a 
   8 * copy of this software and associated documentation files (the "Software"), 
   9 * to deal in the Software without restriction, including without limitation 
  10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
  11 * and/or sell copies of the Software, and to permit persons to whom the 
  12 * Software is furnished to do so, subject to the following conditions:
  13 *
  14 * The above copyright notice and this permission notice shall be included in 
  15 * all copies or substantial portions of the Software.
  16 *
  17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
  18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
  19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
  20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
  21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
  22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
  23 * DEALINGS IN THE SOFTWARE.
  24 */
  25
  26/*
  27 * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
  28 * Please edit Tokenizer.java instead and regenerate.
  29 */
  30
  31#define nsHtml5Tokenizer_cpp__
  32
  33#include "prtypes.h"
  34#include "nsIAtom.h"
  35#include "nsHtml5AtomTable.h"
  36#include "nsString.h"
  37#include "nsIContent.h"
  38#include "nsTraceRefcnt.h"
  39#include "jArray.h"
  40#include "nsHtml5DocumentMode.h"
  41#include "nsHtml5ArrayCopy.h"
  42#include "nsHtml5NamedCharacters.h"
  43#include "nsHtml5NamedCharactersAccel.h"
  44#include "nsHtml5Atoms.h"
  45#include "nsAHtml5TreeBuilderState.h"
  46#include "nsHtml5Macros.h"
  47#include "nsHtml5Highlighter.h"
  48#include "nsHtml5TokenizerLoopPolicies.h"
  49
  50#include "nsHtml5TreeBuilder.h"
  51#include "nsHtml5MetaScanner.h"
  52#include "nsHtml5AttributeName.h"
  53#include "nsHtml5ElementName.h"
  54#include "nsHtml5HtmlAttributes.h"
  55#include "nsHtml5StackNode.h"
  56#include "nsHtml5UTF16Buffer.h"
  57#include "nsHtml5StateSnapshot.h"
  58#include "nsHtml5Portability.h"
  59
  60#include "nsHtml5Tokenizer.h"
  61
  62PRUnichar nsHtml5Tokenizer::LT_GT[] = { '<', '>' };
  63PRUnichar nsHtml5Tokenizer::LT_SOLIDUS[] = { '<', '/' };
  64PRUnichar nsHtml5Tokenizer::RSQB_RSQB[] = { ']', ']' };
  65PRUnichar nsHtml5Tokenizer::REPLACEMENT_CHARACTER[] = { 0xfffd };
  66PRUnichar nsHtml5Tokenizer::LF[] = { '\n' };
  67PRUnichar nsHtml5Tokenizer::CDATA_LSQB[] = { 'C', 'D', 'A', 'T', 'A', '[' };
  68PRUnichar nsHtml5Tokenizer::OCTYPE[] = { 'o', 'c', 't', 'y', 'p', 'e' };
  69PRUnichar nsHtml5Tokenizer::UBLIC[] = { 'u', 'b', 'l', 'i', 'c' };
  70PRUnichar nsHtml5Tokenizer::YSTEM[] = { 'y', 's', 't', 'e', 'm' };
  71static PRUnichar const TITLE_ARR_DATA[] = { 't', 'i', 't', 'l', 'e' };
  72staticJArray<PRUnichar,PRInt32> nsHtml5Tokenizer::TITLE_ARR = { TITLE_ARR_DATA, NS_ARRAY_LENGTH(TITLE_ARR_DATA) };
  73static PRUnichar const SCRIPT_ARR_DATA[] = { 's', 'c', 'r', 'i', 'p', 't' };
  74staticJArray<PRUnichar,PRInt32> nsHtml5Tokenizer::SCRIPT_ARR = { SCRIPT_ARR_DATA, NS_ARRAY_LENGTH(SCRIPT_ARR_DATA) };
  75static PRUnichar const STYLE_ARR_DATA[] = { 's', 't', 'y', 'l', 'e' };
  76staticJArray<PRUnichar,PRInt32> nsHtml5Tokenizer::STYLE_ARR = { STYLE_ARR_DATA, NS_ARRAY_LENGTH(STYLE_ARR_DATA) };
  77static PRUnichar const PLAINTEXT_ARR_DATA[] = { 'p', 'l', 'a', 'i', 'n', 't', 'e', 'x', 't' };
  78staticJArray<PRUnichar,PRInt32> nsHtml5Tokenizer::PLAINTEXT_ARR = { PLAINTEXT_ARR_DATA, NS_ARRAY_LENGTH(PLAINTEXT_ARR_DATA) };
  79static PRUnichar const XMP_ARR_DATA[] = { 'x', 'm', 'p' };
  80staticJArray<PRUnichar,PRInt32> nsHtml5Tokenizer::XMP_ARR = { XMP_ARR_DATA, NS_ARRAY_LENGTH(XMP_ARR_DATA) };
  81static PRUnichar const TEXTAREA_ARR_DATA[] = { 't', 'e', 'x', 't', 'a', 'r', 'e', 'a' };
  82staticJArray<PRUnichar,PRInt32> nsHtml5Tokenizer::TEXTAREA_ARR = { TEXTAREA_ARR_DATA, NS_ARRAY_LENGTH(TEXTAREA_ARR_DATA) };
  83static PRUnichar const IFRAME_ARR_DATA[] = { 'i', 'f', 'r', 'a', 'm', 'e' };
  84staticJArray<PRUnichar,PRInt32> nsHtml5Tokenizer::IFRAME_ARR = { IFRAME_ARR_DATA, NS_ARRAY_LENGTH(IFRAME_ARR_DATA) };
  85static PRUnichar const NOEMBED_ARR_DATA[] = { 'n', 'o', 'e', 'm', 'b', 'e', 'd' };
  86staticJArray<PRUnichar,PRInt32> nsHtml5Tokenizer::NOEMBED_ARR = { NOEMBED_ARR_DATA, NS_ARRAY_LENGTH(NOEMBED_ARR_DATA) };
  87static PRUnichar const NOSCRIPT_ARR_DATA[] = { 'n', 'o', 's', 'c', 'r', 'i', 'p', 't' };
  88staticJArray<PRUnichar,PRInt32> nsHtml5Tokenizer::NOSCRIPT_ARR = { NOSCRIPT_ARR_DATA, NS_ARRAY_LENGTH(NOSCRIPT_ARR_DATA) };
  89static PRUnichar const NOFRAMES_ARR_DATA[] = { 'n', 'o', 'f', 'r', 'a', 'm', 'e', 's' };
  90staticJArray<PRUnichar,PRInt32> nsHtml5Tokenizer::NOFRAMES_ARR = { NOFRAMES_ARR_DATA, NS_ARRAY_LENGTH(NOFRAMES_ARR_DATA) };
  91
  92nsHtml5Tokenizer::nsHtml5Tokenizer(nsHtml5TreeBuilder* tokenHandler, bool viewingXmlSource)
  93  : tokenHandler(tokenHandler),
  94    encodingDeclarationHandler(nsnull),
  95    bmpChar(jArray<PRUnichar,PRInt32>::newJArray(1)),
  96    astralChar(jArray<PRUnichar,PRInt32>::newJArray(2)),
  97    tagName(nsnull),
  98    attributeName(nsnull),
  99    doctypeName(nsnull),
 100    publicIdentifier(nsnull),
 101    systemIdentifier(nsnull),
 102    attributes(nsnull),
 103    viewingXmlSource(viewingXmlSource)
 104{
 105  MOZ_COUNT_CTOR(nsHtml5Tokenizer);
 106}
 107
 108void 
 109nsHtml5Tokenizer::setInterner(nsHtml5AtomTable* interner)
 110{
 111  this->interner = interner;
 112}
 113
 114void 
 115nsHtml5Tokenizer::initLocation(nsString* newPublicId, nsString* newSystemId)
 116{
 117  this->systemId = newSystemId;
 118  this->publicId = newPublicId;
 119}
 120
 121bool 
 122nsHtml5Tokenizer::isViewingXmlSource()
 123{
 124  return viewingXmlSource;
 125}
 126
 127void 
 128nsHtml5Tokenizer::setStateAndEndTagExpectation(PRInt32 specialTokenizerState, nsIAtom* endTagExpectation)
 129{
 130  this->stateSave = specialTokenizerState;
 131  if (specialTokenizerState == NS_HTML5TOKENIZER_DATA) {
 132    return;
 133  }
 134  autoJArray<PRUnichar,PRInt32> asArray = nsHtml5Portability::newCharArrayFromLocal(endTagExpectation);
 135  this->endTagExpectation = nsHtml5ElementName::elementNameByBuffer(asArray, 0, asArray.length, interner);
 136  endTagExpectationToArray();
 137}
 138
 139void 
 140nsHtml5Tokenizer::setStateAndEndTagExpectation(PRInt32 specialTokenizerState, nsHtml5ElementName* endTagExpectation)
 141{
 142  this->stateSave = specialTokenizerState;
 143  this->endTagExpectation = endTagExpectation;
 144  endTagExpectationToArray();
 145}
 146
 147void 
 148nsHtml5Tokenizer::endTagExpectationToArray()
 149{
 150  switch(endTagExpectation->getGroup()) {
 151    case NS_HTML5TREE_BUILDER_TITLE: {
 152      endTagExpectationAsArray = TITLE_ARR;
 153      return;
 154    }
 155    case NS_HTML5TREE_BUILDER_SCRIPT: {
 156      endTagExpectationAsArray = SCRIPT_ARR;
 157      return;
 158    }
 159    case NS_HTML5TREE_BUILDER_STYLE: {
 160      endTagExpectationAsArray = STYLE_ARR;
 161      return;
 162    }
 163    case NS_HTML5TREE_BUILDER_PLAINTEXT: {
 164      endTagExpectationAsArray = PLAINTEXT_ARR;
 165      return;
 166    }
 167    case NS_HTML5TREE_BUILDER_XMP: {
 168      endTagExpectationAsArray = XMP_ARR;
 169      return;
 170    }
 171    case NS_HTML5TREE_BUILDER_TEXTAREA: {
 172      endTagExpectationAsArray = TEXTAREA_ARR;
 173      return;
 174    }
 175    case NS_HTML5TREE_BUILDER_IFRAME: {
 176      endTagExpectationAsArray = IFRAME_ARR;
 177      return;
 178    }
 179    case NS_HTML5TREE_BUILDER_NOEMBED: {
 180      endTagExpectationAsArray = NOEMBED_ARR;
 181      return;
 182    }
 183    case NS_HTML5TREE_BUILDER_NOSCRIPT: {
 184      endTagExpectationAsArray = NOSCRIPT_ARR;
 185      return;
 186    }
 187    case NS_HTML5TREE_BUILDER_NOFRAMES: {
 188      endTagExpectationAsArray = NOFRAMES_ARR;
 189      return;
 190    }
 191    default: {
 192
 193      return;
 194    }
 195  }
 196}
 197
 198void 
 199nsHtml5Tokenizer::setLineNumber(PRInt32 line)
 200{
 201  this->line = line;
 202}
 203
 204nsHtml5HtmlAttributes* 
 205nsHtml5Tokenizer::emptyAttributes()
 206{
 207  return nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES;
 208}
 209
 210void 
 211nsHtml5Tokenizer::appendStrBuf(PRUnichar c)
 212{
 213  if (strBufLen == strBuf.length) {
 214    jArray<PRUnichar,PRInt32> newBuf = jArray<PRUnichar,PRInt32>::newJArray(strBuf.length + NS_HTML5TOKENIZER_BUFFER_GROW_BY);
 215    nsHtml5ArrayCopy::arraycopy(strBuf, newBuf, strBuf.length);
 216    strBuf = newBuf;
 217  }
 218  strBuf[strBufLen++] = c;
 219}
 220
 221nsString* 
 222nsHtml5Tokenizer::strBufToString()
 223{
 224  return nsHtml5Portability::newStringFromBuffer(strBuf, 0, strBufLen);
 225}
 226
 227void 
 228nsHtml5Tokenizer::strBufToDoctypeName()
 229{
 230  doctypeName = nsHtml5Portability::newLocalNameFromBuffer(strBuf, 0, strBufLen, interner);
 231}
 232
 233void 
 234nsHtml5Tokenizer::emitStrBuf()
 235{
 236  if (strBufLen > 0) {
 237    tokenHandler->characters(strBuf, 0, strBufLen);
 238  }
 239}
 240
 241void 
 242nsHtml5Tokenizer::appendLongStrBuf(PRUnichar c)
 243{
 244  if (longStrBufLen == longStrBuf.length) {
 245    jArray<PRUnichar,PRInt32> newBuf = jArray<PRUnichar,PRInt32>::newJArray(longStrBufLen + (longStrBufLen >> 1));
 246    nsHtml5ArrayCopy::arraycopy(longStrBuf, newBuf, longStrBuf.length);
 247    longStrBuf = newBuf;
 248  }
 249  longStrBuf[longStrBufLen++] = c;
 250}
 251
 252void 
 253nsHtml5Tokenizer::appendLongStrBuf(PRUnichar* buffer, PRInt32 offset, PRInt32 length)
 254{
 255  PRInt32 reqLen = longStrBufLen + length;
 256  if (longStrBuf.length < reqLen) {
 257    jArray<PRUnichar,PRInt32> newBuf = jArray<PRUnichar,PRInt32>::newJArray(reqLen + (reqLen >> 1));
 258    nsHtml5ArrayCopy::arraycopy(longStrBuf, newBuf, longStrBuf.length);
 259    longStrBuf = newBuf;
 260  }
 261  nsHtml5ArrayCopy::arraycopy(buffer, offset, longStrBuf, longStrBufLen, length);
 262  longStrBufLen = reqLen;
 263}
 264
 265nsString* 
 266nsHtml5Tokenizer::longStrBufToString()
 267{
 268  return nsHtml5Portability::newStringFromBuffer(longStrBuf, 0, longStrBufLen);
 269}
 270
 271void 
 272nsHtml5Tokenizer::emitComment(PRInt32 provisionalHyphens, PRInt32 pos)
 273{
 274  tokenHandler->comment(longStrBuf, 0, longStrBufLen - provisionalHyphens);
 275  cstart = pos + 1;
 276}
 277
 278void 
 279nsHtml5Tokenizer::flushChars(PRUnichar* buf, PRInt32 pos)
 280{
 281  if (pos > cstart) {
 282    tokenHandler->characters(buf, cstart, pos - cstart);
 283  }
 284  cstart = PR_INT32_MAX;
 285}
 286
 287void 
 288nsHtml5Tokenizer::resetAttributes()
 289{
 290  attributes = nsnull;
 291}
 292
 293void 
 294nsHtml5Tokenizer::strBufToElementNameString()
 295{
 296  tagName = nsHtml5ElementName::elementNameByBuffer(strBuf, 0, strBufLen, interner);
 297}
 298
 299PRInt32 
 300nsHtml5Tokenizer::emitCurrentTagToken(bool selfClosing, PRInt32 pos)
 301{
 302  cstart = pos + 1;
 303  maybeErrSlashInEndTag(selfClosing);
 304  stateSave = NS_HTML5TOKENIZER_DATA;
 305  nsHtml5HtmlAttributes* attrs = (!attributes ? nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES : attributes);
 306  if (endTag) {
 307    maybeErrAttributesOnEndTag(attrs);
 308    if (!viewingXmlSource) {
 309      tokenHandler->endTag(tagName);
 310    }
 311    delete attributes;
 312  } else {
 313    if (viewingXmlSource) {
 314      delete attributes;
 315    } else {
 316      tokenHandler->startTag(tagName, attrs, selfClosing);
 317    }
 318  }
 319  tagName->release();
 320  tagName = nsnull;
 321  resetAttributes();
 322  return stateSave;
 323}
 324
 325void 
 326nsHtml5Tokenizer::attributeNameComplete()
 327{
 328  attributeName = nsHtml5AttributeName::nameByBuffer(strBuf, 0, strBufLen, interner);
 329  if (!attributes) {
 330    attributes = new nsHtml5HtmlAttributes(0);
 331  }
 332  if (attributes->contains(attributeName)) {
 333    errDuplicateAttribute();
 334    attributeName->release();
 335    attributeName = nsnull;
 336  }
 337}
 338
 339void 
 340nsHtml5Tokenizer::addAttributeWithoutValue()
 341{
 342
 343  if (attributeName) {
 344    attributes->addAttribute(attributeName, nsHtml5Portability::newEmptyString());
 345    attributeName = nsnull;
 346  }
 347}
 348
 349void 
 350nsHtml5Tokenizer::addAttributeWithValue()
 351{
 352  if (attributeName) {
 353    nsString* val = longStrBufToString();
 354    if (mViewSource) {
 355      mViewSource->MaybeLinkifyAttributeValue(attributeName, val);
 356    }
 357    attributes->addAttribute(attributeName, val);
 358    attributeName = nsnull;
 359  }
 360}
 361
 362void 
 363nsHtml5Tokenizer::start()
 364{
 365  initializeWithoutStarting();
 366  tokenHandler->startTokenization(this);
 367}
 368
 369bool 
 370nsHtml5Tokenizer::tokenizeBuffer(nsHtml5UTF16Buffer* buffer)
 371{
 372  PRInt32 state = stateSave;
 373  PRInt32 returnState = returnStateSave;
 374  PRUnichar c = '\0';
 375  shouldSuspend = false;
 376  lastCR = false;
 377  PRInt32 start = buffer->getStart();
 378  PRInt32 pos = start - 1;
 379  switch(state) {
 380    case NS_HTML5TOKENIZER_DATA:
 381    case NS_HTML5TOKENIZER_RCDATA:
 382    case NS_HTML5TOKENIZER_SCRIPT_DATA:
 383    case NS_HTML5TOKENIZER_PLAINTEXT:
 384    case NS_HTML5TOKENIZER_RAWTEXT:
 385    case NS_HTML5TOKENIZER_CDATA_SECTION:
 386    case NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED:
 387    case NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPE_START:
 388    case NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPE_START_DASH:
 389    case NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_DASH:
 390    case NS_HTML5TOKENIZER_SCRIPT_DATA_ESCAPED_DASH_DASH:
 391    case NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPE_START:
 392    case NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPED:
 393    case NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:
 394    case NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPED_DASH:
 395    case NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:
 396    case NS_HTML5TOKENIZER_SCRIPT_DATA_DOUBLE_ESCAPE_END: {
 397      cstart = start;
 398      break;
 399    }
 400    default: {
 401      cstart = PR_INT32_MAX;
 402      break;
 403    }
 404  }
 405  if (mViewSource) {
 406    mViewSource->SetBuffer(buffer);
 407    pos = stateLoop<nsHtml5ViewSourcePolicy>(state, c, pos, buffer->getBuffer(), false, returnState, buffer->getEnd());
 408    mViewSource->DropBuffer((pos == buffer->getEnd()) ? pos : pos + 1);
 409  } else {
 410    pos = stateLoop<nsHtml5SilentPolicy>(state, c, pos, buffer->getBuffer(), false, returnState, buffer->getEnd());
 411  }
 412  if (pos == buffer->getEnd()) {
 413    buffer->setStart(pos);
 414  } else {
 415    buffer->setStart(pos + 1);
 416  }
 417  return lastCR;
 418}
 419
 420template<class P>
 421PRInt32 
 422nsHtml5Tokenizer::stateLoop(PRInt32 state, PRUnichar c, PRInt32 pos, PRUnichar* buf, bool reconsume, PRInt32 returnState, PRInt32 endPos)
 423{
 424  stateloop: for (; ; ) {
 425    switch(state) {
 426      case NS_HTML5TOKENIZER_DATA: {
 427        for (; ; ) {
 428          if (reconsume) {
 429            reconsume = false;
 430          } else {
 431            if (++pos == endPos) {
 432              NS_HTML5_BREAK(stateloop);
 433            }
 434            c = checkChar(buf, pos);
 435          }
 436          switch(c) {
 437            case '&': {
 438              flushChars(buf, pos);
 439              clearStrBufAndAppend(c);
 440              setAdditionalAndRememberAmpersandLocation('\0');
 441              returnState = state;
 442              state = P::transition(mViewSource, NS_HTML5TOKENIZER_CONSUME_CHARACTER_REFERENCE, reconsume, pos);
 443              NS_HTML5_CONTINUE(stateloop);
 444            }
 445            case '<': {
 446              flushChars(buf, pos);
 447              state = P::transition(mViewSource, NS_HTML5TOKENIZER_TAG_OPEN, reconsume, pos);
 448              NS_HTML5_BREAK(dataloop);
 449            }
 450            case '\0': {
 451              emitReplacementCharacter(buf, pos);
 452              continue;
 453            }
 454            case '\r': {
 455              emitCarriageReturn(buf, pos);
 456              NS_HTML5_BREAK(stateloop);
 457            }
 458            case '\n': {
 459              silentLineFeed();
 460            }
 461            default: {
 462              continue;
 463            }
 464          }
 465        }
 466        dataloop_end: ;
 467      }
 468      case NS_HTML5TOKENIZER_TAG_OPEN: {
 469        for (; ; ) {
 470          if (++pos == endPos) {
 471            NS_HTML5_BREAK(stateloop);
 472          }
 473          c = checkChar(buf, pos);
 474          if (c >= 'A' && c <= 'Z') {
 475            endTag = false;
 476            clearStrBufAndAppend((PRUnichar) (c + 0x20));
 477            state = P::transition(mViewSource, NS_HTML5TOKENIZER_TAG_NAME, reconsume, pos);
 478            NS_HTML5_BREAK(tagopenloop);
 479          } else if (c >= 'a' && c <= 'z') {
 480            endTag = false;
 481            clearStrBufAndAppend(c);
 482            state = P::transition(mViewSource, NS_HTML5TOKENIZER_TAG_NAME, reconsume, pos);
 483            NS_HTML5_BREAK(tagopenloop);
 484          }
 485          switch(c) {
 486            case '!': {
 487              state = P::transition(mViewSource, NS_HTML5TOKENIZER_MARKUP_DECLARATION_OPEN, reconsume, pos);
 488              NS_HTML5_CONTINUE(stateloop);
 489            }
 490            case '/': {
 491              state = P::transition(mViewSource, NS_HTML5TOKENIZER_CLOSE_TAG_OPEN, reconsume, pos);
 492              NS_HTML5_CONTINUE(stateloop);
 493            }
 494            case '\?': {
 495              if (viewingXmlSource) {
 496                state = P::transition(mViewSource, NS_HTML5TOKENIZER_PROCESSING_INSTRUCTION, reconsume, pos);
 497                NS_HTML5_CONTINUE(stateloop);
 498              }
 499              if (P::reportErrors) {
 500                errProcessingInstruction();
 501              }
 502              clearLongStrBufAndAppend(c);
 503              state = P::transition(mViewSource, NS_HTML5TOKENIZER_BOGUS_COMMENT, reconsume, pos);
 504              NS_HTML5_CONTINUE(stateloop);
 505            }
 506            case '>': {
 507              if (P::reportErrors) {
 508                errLtGt();
 509              }
 510              tokenHandler->characters(nsHtml5Tokenizer::LT_GT, 0, 2);
 511              cstart = pos + 1;
 512              state = P::transition(mViewSource, NS_HTML5TOKENIZER_DATA, reconsume, pos);
 513              NS_HTML5_CONTINUE(stateloop);
 514            }
 515            default: {
 516              if (P::reportErrors) {
 517                errBadCharAfterLt(c);
 518              }
 519              tokenHandler->characters(nsHtml5Tokenizer::LT_GT, 0, 1);
 520              cstart = pos;
 521              reconsume = true;
 522              state = P::transition(mViewSource, NS_HTML5TOKENIZER_DATA, reconsume, pos);
 523              NS_HTML5_CONTINUE(stateloop);
 524            }
 525          }
 526        }
 527        tagopenloop_end: ;
 528      }
 529      case NS_HTML5TOKENIZER_TAG_NAME: {
 530        for (; ; ) {
 531          if (++pos == endPos) {
 532            NS_HTML5_BREAK(stateloop);
 533          }
 534          c = checkChar(buf, pos);
 535          switch(c) {
 536            case '\r': {
 537              silentCarriageReturn();
 538              strBufToElementNameString();
 539              state = P::transition(mViewSource, NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME, reconsume, pos);
 540              NS_HTML5_BREAK(stateloop);
 541            }
 542            case '\n': {
 543              silentLineFeed();
 544            }
 545            case ' ':
 546            case '\t':
 547            case '\f': {
 548              strBufToElementNameString();
 549              state = P::transition(mViewSource, NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME, reconsume, pos);
 550              NS_HTML5_BREAK(tagnameloop);
 551            }
 552            case '/': {
 553              strBufToElementNameString();
 554              state = P::transition(mViewSource, NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG, reconsume, pos);
 555              NS_HTML5_CONTINUE(stateloop);
 556            }
 557            case '>': {
 558              strBufToElementNameString();
 559              state = P::transition(mViewSource, emitCurrentTagToken(false, pos), reconsume, pos);
 560              if (shouldSuspend) {
 561                NS_HTML5_BREAK(stateloop);
 562              }
 563              NS_HTML5_CONTINUE(stateloop);
 564            }
 565            case '\0': {
 566              c = 0xfffd;
 567            }
 568            default: {
 569              if (c >= 'A' && c <= 'Z') {
 570                c += 0x20;
 571              }
 572              appendStrBuf(c);
 573              continue;
 574            }
 575          }
 576        }
 577        tagnameloop_end: ;
 578      }
 579      case NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME: {
 580        for (; ; ) {
 581          if (reconsume) {
 582            reconsume = false;
 583          } else {
 584            if (++pos == endPos) {
 585              NS_HTML5_BREAK(stateloop);
 586            }
 587            c = checkChar(buf, pos);
 588          }
 589          switch(c) {
 590            case '\r': {
 591              silentCarriageReturn();
 592              NS_HTML5_BREAK(stateloop);
 593            }
 594            case '\n': {
 595              silentLineFeed();
 596            }
 597            case ' ':
 598            case '\t':
 599            case '\f': {
 600              continue;
 601            }
 602            case '/': {
 603              state = P::transition(mViewSource, NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG, reconsume, pos);
 604              NS_HTML5_CONTINUE(stateloop);
 605            }
 606            case '>': {
 607              state = P::transition(mViewSource, emitCurrentTagToken(false, pos), reconsume, pos);
 608              if (shouldSuspend) {
 609                NS_HTML5_BREAK(stateloop);
 610              }
 611              NS_HTML5_CONTINUE(stateloop);
 612            }
 613            case '\0': {
 614              c = 0xfffd;
 615            }
 616            case '\"':
 617            case '\'':
 618            case '<':
 619            case '=': {
 620              if (P::reportErrors) {
 621                errBadCharBeforeAttributeNameOrNull(c);
 622              }
 623            }
 624            default: {
 625              if (c >= 'A' && c <= 'Z') {
 626                c += 0x20;
 627              }
 628              clearStrBufAndAppend(c);
 629              state = P::transition(mViewSource, NS_HTML5TOKENIZER_ATTRIBUTE_NAME, reconsume, pos);
 630              NS_HTML5_BREAK(beforeattributenameloop);
 631            }
 632          }
 633        }
 634        beforeattributenameloop_end: ;
 635      }
 636      case NS_HTML5TOKENIZER_ATTRIBUTE_NAME: {
 637        for (; ; ) {
 638          if (++pos == endPos) {
 639            NS_HTML5_BREAK(stateloop);
 640          }
 641          c = checkChar(buf, pos);
 642          switch(c) {
 643            case '\r': {
 644              silentCarriageReturn();
 645              attributeNameComplete();
 646              state = P::transition(mViewSource, NS_HTML5TOKENIZER_AFTER_ATTRIBUTE_NAME, reconsume, pos);
 647              NS_HTML5_BREAK(stateloop);
 648            }
 649            case '\n': {
 650              silentLineFeed();
 651            }
 652            case ' ':
 653            case '\t':
 654            case '\f': {
 655              attributeNameComplete();
 656              state = P::transition(mViewSource, NS_HTML5TOKENIZER_AFTER_ATTRIBUTE_NAME, reconsume, pos);
 657              NS_HTML5_CONTINUE(stateloop);
 658            }
 659            case '/': {
 660              attributeNameComplete();
 661              addAttributeWithoutValue();
 662              state = P::transition(mViewSource, NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG, reconsume, pos);
 663              NS_HTML5_CONTINUE(stateloop);
 664            }
 665            case '=': {
 666              attributeNameComplete();
 667              state = P::transition(mViewSource, NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_VALUE, reconsume, pos);
 668              NS_HTML5_BREAK(attributenameloop);
 669            }
 670            case '>': {
 671              attributeNameComplete();
 672              addAttributeWithoutValue();
 673              state = P::transition(mViewSource, emitCurrentTagToken(false, pos), reconsume, pos);
 674              if (shouldSuspend) {
 675                NS_HTML5_BREAK(stateloop);
 676              }
 677              NS_HTML5_CONTINUE(stateloop);
 678            }
 679            case '\0': {
 680              c = 0xfffd;
 681            }
 682            case '\"':
 683            case '\'':
 684            case '<': {
 685              if (P::reportErrors) {
 686                errQuoteOrLtInAttributeNameOrNull(c);
 687              }
 688            }
 689            default: {
 690              if (c >= 'A' && c <= 'Z') {
 691                c += 0x20;
 692              }
 693              appendStrBuf(c);
 694              continue;
 695            }
 696          }
 697        }
 698        attributenameloop_end: ;
 699      }
 700      case NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_VALUE: {
 701        for (; ; ) {
 702          if (++pos == endPos) {
 703            NS_HTML5_BREAK(stateloop);
 704          }
 705          c = checkChar(buf, pos);
 706          switch(c) {
 707            case '\r': {
 708              silentCarriageReturn();
 709              NS_HTML5_BREAK(stateloop);
 710            }
 711            case '\n': {
 712              silentLineFeed();
 713            }
 714            case ' ':
 715            case '\t':
 716            case '\f': {
 717              continue;
 718            }
 719            case '\"': {
 720              clearLongStrBuf();
 721              state = P::transition(mViewSource, NS_HTML5TOKENIZER_ATTRIBUTE_VALUE_DOUBLE_QUOTED, reconsume, pos);
 722              NS_HTML5_BREAK(beforeattributevalueloop);
 723            }
 724            case '&': {
 725              clearLongStrBuf();
 726              reconsume = true;
 727              state = P::transition(mViewSource, NS_HTML5TOKENIZER_ATTRIBUTE_VALUE_UNQUOTED, reconsume, pos);
 728
 729              NS_HTML5_CONTINUE(stateloop);
 730            }
 731            case '\'': {
 732              clearLongStrBuf();
 733              state = P::transition(mViewSource, NS_HTML5TOKENIZER_ATTRIBUTE_VALUE_SINGLE_QUOTED, reconsume, pos);
 734              NS_HTML5_CONTINUE(stateloop);
 735            }
 736            case '>': {
 737              if (P::reportErrors) {
 738                errAttributeValueMissing();
 739              }
 740              addAttributeWithoutValue();
 741              state = P::transition(mViewSource, emitCurrentTagToken(false, pos), reconsume, pos);
 742              if (shouldSuspend) {
 743                NS_HTML5_BREAK(stateloop);
 744              }
 745              NS_HTML5_CONTINUE(stateloop);
 746            }
 747            case '\0': {
 748              c = 0xfffd;
 749            }
 750            case '<':
 751            case '=':
 752            case '`': {
 753              if (P::reportErrors) {
 754                errLtOrEqualsOrGraveInUnquotedAttributeOrNull(c);
 755              }
 756            }
 757            default: {
 758              clearLongStrBufAndAppend(c);
 759              state = P::transition(mViewSource, NS_HTML5TOKENIZER_ATTRIBUTE_VALUE_UNQUOTED, reconsume, pos);
 760
 761              NS_HTML5_CONTINUE(stateloop);
 762            }
 763          }
 764        }
 765        beforeattributevalueloop_end: ;
 766      }
 767      case NS_HTML5TOKENIZER_ATTRIBUTE_VALUE_DOUBLE_QUOTED: {
 768        for (; ; ) {
 769          if (reconsume) {
 770            reconsume = false;
 771          } else {
 772            if (++pos == endPos) {
 773              NS_HTML5_BREAK(stateloop);
 774            }
 775            c = checkChar(buf, pos);
 776          }
 777          switch(c) {
 778            case '\"': {
 779              addAttributeWithValue();
 780              state = P::transition(mViewSource, NS_HTML5TOKENIZER_AFTER_ATTRIBUTE_VALUE_QUOTED, reconsume, pos);
 781              NS_HTML5_BREAK(attributevaluedoublequotedloop);
 782            }
 783            case '&': {
 784              clearStrBufAndAppend(c);
 785              setAdditionalAndRememberAmpersandLocation('\"');
 786              returnState = state;
 787              state = P::transition(mViewSource, NS_HTML5TOKENIZER_CONSUME_CHARACTER_REFERENCE, reconsume, pos);
 788              NS_HTML5_CONTINUE(stateloop);
 789            }
 790            case '\r': {
 791              appendLongStrBufCarriageReturn();
 792              NS_HTML5_BREAK(stateloop);
 793            }
 794            case '\n': {
 795              appendLongStrBufLineFeed();
 796              continue;
 797            }
 798            case '\0': {
 799              c = 0xfffd;
 800            }
 801            default: {
 802              appendLongStrBuf(c);
 803              continue;
 804            }
 805          }
 806        }
 807        attributevaluedoublequotedloop_end: ;
 808      }
 809      case NS_HTML5TOKENIZER_AFTER_ATTRIBUTE_VALUE_QUOTED: {
 810        for (; ; ) {
 811          if (++pos == endPos) {
 812            NS_HTML5_BREAK(stateloop);
 813          }
 814          c = checkChar(buf, pos);
 815          switch(c) {
 816            case '\r': {
 817              silentCarriageReturn();
 818              state = P::transition(mViewSource, NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME, reconsume, pos);
 819              NS_HTML5_BREAK(stateloop);
 820            }
 821            case '\n': {
 822              silentLineFeed();
 823            }
 824            case ' ':
 825            case '\t':
 826            case '\f': {
 827              state = P::transition(mViewSource, NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME, reconsume, pos);
 828              NS_HTML5_CONTINUE(stateloop);
 829            }
 830            case '/': {
 831              state = P::transition(mViewSource, NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG, reconsume, pos);
 832              NS_HTML5_BREAK(afterattributevaluequotedloop);
 833            }
 834            case '>': {
 835              state = P::transition(mViewSource, emitCurrentTagToken(false, pos), reconsume, pos);
 836              if (shouldSuspend) {
 837                NS_HTML5_BREAK(stateloop);
 838              }
 839              NS_HTML5_CONTINUE(stateloop);
 840            }
 841            default: {
 842              if (P::reportErrors) {
 843                errNoSpaceBetweenAttributes();
 844              }
 845              reconsume = true;
 846              state = P::transition(mViewSource, NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME, reconsume, pos);
 847              NS_HTML5_CONTINUE(stateloop);
 848            }
 849          }
 850        }
 851        afterattributevaluequotedloop_end: ;
 852      }
 853      case NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG: {
 854        if (++pos == endPos) {
 855          NS_HTML5_BREAK(stateloop);
 856        }
 857        c = checkChar(buf, pos);
 858        switch(c) {
 859          case '>': {
 860            state = P::transition(mViewSource, emitCurrentTagToken(true, pos), reconsume, pos);
 861            if (shouldSuspend) {
 862              NS_HTML5_BREAK(stateloop);
 863            }
 864            NS_HTML5_CONTINUE(stateloop);
 865          }
 866          default: {
 867            if (P::reportErrors) {
 868              errSlashNotFollowedByGt();
 869            }
 870            reconsume = true;
 871            state = P::transition(mViewSource, NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME, reconsume, pos);
 872            NS_HTML5_CONTINUE(stateloop);
 873          }
 874        }
 875      }
 876      case NS_HTML5TOKENIZER_ATTRIBUTE_VALUE_UNQUOTED: {
 877        for (; ; ) {
 878          if (reconsume) {
 879            reconsume = false;
 880          } else {
 881            if (++pos == endPos) {
 882              NS_HTML5_BREAK(stateloop);
 883            }
 884            c = checkChar(buf, pos);
 885          }
 886          switch(c) {
 887            case '\r': {
 888              silentCarriageReturn();
 889              addAttributeWithValue();
 890              state = P::transition(mViewSource, NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME, reconsume, pos);
 891              NS_HTML5_BREAK(stateloop);
 892            }
 893            case '\n': {
 894              silentLineFeed();
 895            }
 896            case ' ':
 897            case '\t':
 898            case '\f': {
 899              addAttributeWithValue();
 900              state = P::transition(mViewSource, NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_NAME, reconsume, pos);
 901              NS_HTML5_CONTINUE(stateloop);
 902            }
 903            case '&': {
 904              clearStrBufAndAppend(c);
 905              setAdditionalAndRememberAmpersandLocation('>');
 906              returnState = state;
 907              state = P::transition(mViewSource, NS_HTML5TOKENIZER_CONSUME_CHARACTER_REFERENCE, reconsume, pos);
 908              NS_HTML5_CONTINUE(stateloop);
 909            }
 910            case '>': {
 911              addAttributeWithValue();
 912              state = P::transition(mViewSource, emitCurrentTagToken(false, pos), reconsume, pos);
 913              if (shouldSuspend) {
 914                NS_HTML5_BREAK(stateloop);
 915              }
 916              NS_HTML5_CONTINUE(stateloop);
 917            }
 918            case '\0': {
 919              c = 0xfffd;
 920            }
 921            case '<':
 922            case '\"':
 923            case '\'':
 924            case '=':
 925            case '`': {
 926              if (P::reportErrors) {
 927                errUnquotedAttributeValOrNull(c);
 928              }
 929            }
 930            default: {
 931
 932              appendLongStrBuf(c);
 933              continue;
 934            }
 935          }
 936        }
 937      }
 938      case NS_HTML5TOKENIZER_AFTER_ATTRIBUTE_NAME: {
 939        for (; ; ) {
 940          if (++pos == endPos) {
 941            NS_HTML5_BREAK(stateloop);
 942          }
 943          c = checkChar(buf, pos);
 944          switch(c) {
 945            case '\r': {
 946              silentCarriageReturn();
 947              NS_HTML5_BREAK(stateloop);
 948            }
 949            case '\n': {
 950              silentLineFeed();
 951            }
 952            case ' ':
 953            case '\t':
 954            case '\f': {
 955              continue;
 956            }
 957            case '/': {
 958              addAttributeWithoutValue();
 959              state = P::transition(mViewSource, NS_HTML5TOKENIZER_SELF_CLOSING_START_TAG, reconsume, pos);
 960              NS_HTML5_CONTINUE(stateloop);
 961            }
 962            case '=': {
 963              state = P::transition(mViewSource, NS_HTML5TOKENIZER_BEFORE_ATTRIBUTE_VALUE, reconsume, pos);
 964              NS_HTML5_CONTINUE(stateloop);
 965            }
 966            case '>': {
 967              addAttributeWithoutValue();
 968              state = P::transition(mViewSource, emitCurrentTagToken(false, pos), reconsume, pos);
 969              if (shouldSuspend) {
 970                NS_HTML5_BREAK(stateloop);
 971              }
 972              NS_HTML5_CONTINUE(stateloop);
 973            }
 974            case '\0': {
 975              c = 0xfffd;
 976            }
 977            case '\"':
 978            case '\'':
 979            case '<': {
 980              if (P::reportErrors) {
 981                errQuoteOrLtInAttributeNameOrNull(c);
 982              }
 983            }
 984            default: {
 985              addAttributeWithoutValue();
 986              if (c >= 'A' && c <= 'Z') {
 987                c += 0x20;
 988              }
 989              clearStrBufAndAppend(c);
 990              state = P::transition(mViewSource, NS_HTML5TOKENIZER_ATTRIBUTE_NAME, reconsume, pos);
 991              NS_HTML5_CONTINUE(stateloop);
 992            }
 993          }
 994        }
 995      }
 996      case NS_HTML5TOKENIZER_MARKUP_DECLARATION_OPEN: {
 997        for (; ; ) {
 998          if (++pos == endPos) {
 999            NS_HTML5_BREAK(stateloop);
1000          }
1001          c = checkChar(buf, pos);
1002          switch(c) {
1003            case '-': {
1004              clearLongStrBufAndAppend(c);
1005              state = P::transition(mViewSource, NS_HTML5TOKENIZER_MARKUP_DECLARATION_HYPHEN, reconsume, pos);
1006              NS_HTML5_BREAK(markupdeclarationopenloop);
1007            }
1008            case 'd':
1009            case 'D': {
1010              clearLongStrBufAndAppend(c);
1011              index = 0;
1012              state = P::transition(mViewSource, NS_HTML5TOKENIZER_MARKUP_DECLARATION_OCTYPE, reconsume, pos);
1013              NS_HTML5_CONTINUE(stateloop);
1014            }
1015            case '[': {
1016              if (tokenHandler->cdataSectionAllowed()) {
1017                clearLongStrBufAndAppend(c);
1018                index = 0;
1019                state = P::transition(mViewSource, NS_HTML5TOKENIZER_CDATA_START, reconsume, pos);
1020                NS_HTML5_CONTINUE(stateloop);
1021              }
1022            }
1023            default: {
1024              if (P::reportErrors) {
1025                errBogusComment();
1026              }
1027              clearLongStrBuf();
1028              reconsume = true;
1029              state = P::transition(mViewSource, NS_HTML5TOKENIZER_BOGUS_COMMENT, reconsume, pos);
1030              NS_HTML5_CONTINUE(stateloop);
1031            }
1032          }
1033        }
1034        markupdeclarationopenloop_end: ;
1035      }
1036      case NS_HTML5TOKENIZER_MARKUP_DECLARATION_HYPHEN: {
1037        for (; ; ) {
1038          if (++pos == endPos) {
1039            NS_HTML5_BREAK(stateloop);
1040          }
1041          c = checkChar(buf, pos);
1042          switch(c) {
1043            case '\0': {
1044              NS_HTML5_BREAK(stateloop);
1045            }
1046            case '-': {
1047              clearLongStrBuf();
1048              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT_START, reconsume, pos);
1049              NS_HTML5_BREAK(markupdeclarationhyphenloop);
1050            }
1051            default: {
1052              if (P::reportErrors) {
1053                errBogusComment();
1054              }
1055              reconsume = true;
1056              state = P::transition(mViewSource, NS_HTML5TOKENIZER_BOGUS_COMMENT, reconsume, pos);
1057              NS_HTML5_CONTINUE(stateloop);
1058            }
1059          }
1060        }
1061        markupdeclarationhyphenloop_end: ;
1062      }
1063      case NS_HTML5TOKENIZER_COMMENT_START: {
1064        for (; ; ) {
1065          if (++pos == endPos) {
1066            NS_HTML5_BREAK(stateloop);
1067          }
1068          c = checkChar(buf, pos);
1069          switch(c) {
1070            case '-': {
1071              appendLongStrBuf(c);
1072              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT_START_DASH, reconsume, pos);
1073              NS_HTML5_CONTINUE(stateloop);
1074            }
1075            case '>': {
1076              if (P::reportErrors) {
1077                errPrematureEndOfComment();
1078              }
1079              emitComment(0, pos);
1080              state = P::transition(mViewSource, NS_HTML5TOKENIZER_DATA, reconsume, pos);
1081              NS_HTML5_CONTINUE(stateloop);
1082            }
1083            case '\r': {
1084              appendLongStrBufCarriageReturn();
1085              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT, reconsume, pos);
1086              NS_HTML5_BREAK(stateloop);
1087            }
1088            case '\n': {
1089              appendLongStrBufLineFeed();
1090              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT, reconsume, pos);
1091              NS_HTML5_BREAK(commentstartloop);
1092            }
1093            case '\0': {
1094              c = 0xfffd;
1095            }
1096            default: {
1097              appendLongStrBuf(c);
1098              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT, reconsume, pos);
1099              NS_HTML5_BREAK(commentstartloop);
1100            }
1101          }
1102        }
1103        commentstartloop_end: ;
1104      }
1105      case NS_HTML5TOKENIZER_COMMENT: {
1106        for (; ; ) {
1107          if (++pos == endPos) {
1108            NS_HTML5_BREAK(stateloop);
1109          }
1110          c = checkChar(buf, pos);
1111          switch(c) {
1112            case '-': {
1113              appendLongStrBuf(c);
1114              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT_END_DASH, reconsume, pos);
1115              NS_HTML5_BREAK(commentloop);
1116            }
1117            case '\r': {
1118              appendLongStrBufCarriageReturn();
1119              NS_HTML5_BREAK(stateloop);
1120            }
1121            case '\n': {
1122              appendLongStrBufLineFeed();
1123              continue;
1124            }
1125            case '\0': {
1126              c = 0xfffd;
1127            }
1128            default: {
1129              appendLongStrBuf(c);
1130              continue;
1131            }
1132          }
1133        }
1134        commentloop_end: ;
1135      }
1136      case NS_HTML5TOKENIZER_COMMENT_END_DASH: {
1137        for (; ; ) {
1138          if (++pos == endPos) {
1139            NS_HTML5_BREAK(stateloop);
1140          }
1141          c = checkChar(buf, pos);
1142          switch(c) {
1143            case '-': {
1144              appendLongStrBuf(c);
1145              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT_END, reconsume, pos);
1146              NS_HTML5_BREAK(commentenddashloop);
1147            }
1148            case '\r': {
1149              appendLongStrBufCarriageReturn();
1150              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT, reconsume, pos);
1151              NS_HTML5_BREAK(stateloop);
1152            }
1153            case '\n': {
1154              appendLongStrBufLineFeed();
1155              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT, reconsume, pos);
1156              NS_HTML5_CONTINUE(stateloop);
1157            }
1158            case '\0': {
1159              c = 0xfffd;
1160            }
1161            default: {
1162              appendLongStrBuf(c);
1163              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT, reconsume, pos);
1164              NS_HTML5_CONTINUE(stateloop);
1165            }
1166          }
1167        }
1168        commentenddashloop_end: ;
1169      }
1170      case NS_HTML5TOKENIZER_COMMENT_END: {
1171        for (; ; ) {
1172          if (++pos == endPos) {
1173            NS_HTML5_BREAK(stateloop);
1174          }
1175          c = checkChar(buf, pos);
1176          switch(c) {
1177            case '>': {
1178              emitComment(2, pos);
1179              state = P::transition(mViewSource, NS_HTML5TOKENIZER_DATA, reconsume, pos);
1180              NS_HTML5_CONTINUE(stateloop);
1181            }
1182            case '-': {
1183              adjustDoubleHyphenAndAppendToLongStrBufAndErr(c);
1184              continue;
1185            }
1186            case '\r': {
1187              adjustDoubleHyphenAndAppendToLongStrBufCarriageReturn();
1188              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT, reconsume, pos);
1189              NS_HTML5_BREAK(stateloop);
1190            }
1191            case '\n': {
1192              adjustDoubleHyphenAndAppendToLongStrBufLineFeed();
1193              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT, reconsume, pos);
1194              NS_HTML5_CONTINUE(stateloop);
1195            }
1196            case '!': {
1197              if (P::reportErrors) {
1198                errHyphenHyphenBang();
1199              }
1200              appendLongStrBuf(c);
1201              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT_END_BANG, reconsume, pos);
1202              NS_HTML5_CONTINUE(stateloop);
1203            }
1204            case '\0': {
1205              c = 0xfffd;
1206            }
1207            default: {
1208              adjustDoubleHyphenAndAppendToLongStrBufAndErr(c);
1209              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT, reconsume, pos);
1210              NS_HTML5_CONTINUE(stateloop);
1211            }
1212          }
1213        }
1214
1215      }
1216      case NS_HTML5TOKENIZER_COMMENT_END_BANG: {
1217        for (; ; ) {
1218          if (++pos == endPos) {
1219            NS_HTML5_BREAK(stateloop);
1220          }
1221          c = checkChar(buf, pos);
1222          switch(c) {
1223            case '>': {
1224              emitComment(3, pos);
1225              state = P::transition(mViewSource, NS_HTML5TOKENIZER_DATA, reconsume, pos);
1226              NS_HTML5_CONTINUE(stateloop);
1227            }
1228            case '-': {
1229              appendLongStrBuf(c);
1230              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT_END_DASH, reconsume, pos);
1231              NS_HTML5_CONTINUE(stateloop);
1232            }
1233            case '\r': {
1234              appendLongStrBufCarriageReturn();
1235              NS_HTML5_BREAK(stateloop);
1236            }
1237            case '\n': {
1238              appendLongStrBufLineFeed();
1239              continue;
1240            }
1241            case '\0': {
1242              c = 0xfffd;
1243            }
1244            default: {
1245              appendLongStrBuf(c);
1246              state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT, reconsume, pos);
1247              NS_HTML5_CONTINUE(stateloop);
1248            }
1249          }
1250        }
1251      }
1252      case NS_HTML5TOKENIZER_COMMENT_START_DASH: {
1253        if (++pos == endPos) {
1254          NS_HTML5_BREAK(stateloop);
1255        }
1256        c = checkChar(buf, pos);
1257        switch(c) {
1258          case '-': {
1259            appendLongStrBuf(c);
1260            state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT_END, reconsume, pos);
1261            NS_HTML5_CONTINUE(stateloop);
1262          }
1263          case '>': {
1264            if (P::reportErrors) {
1265              errPrematureEndOfComment();
1266            }
1267            emitComment(1, pos);
1268            state = P::transition(mViewSource, NS_HTML5TOKENIZER_DATA, reconsume, pos);
1269            NS_HTML5_CONTINUE(stateloop);
1270          }
1271          case '\r': {
1272            appendLongStrBufCarriageReturn();
1273            state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT, reconsume, pos);
1274            NS_HTML5_BREAK(stateloop);
1275          }
1276          case '\n': {
1277            appendLongStrBufLineFeed();
1278            state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT, reconsume, pos);
1279            NS_HTML5_CONTINUE(stateloop);
1280          }
1281          case '\0': {
1282            c = 0xfffd;
1283          }
1284          default: {
1285            appendLongStrBuf(c);
1286            state = P::transition(mViewSource, NS_HTML5TOKENIZER_COMMENT, reconsume, pos);
1287            NS_HTML5_CONTINUE(stateloop);
1288          }
1289        }
1290      }
1291      case NS_HTML5TOKENIZER_CDATA_START: {
1292        for (; ; ) {
1293          if (++pos == endPos) {
1294            NS_HTML5_BREAK(stateloop);
1295          }
1296          c = checkChar(buf, pos);
1297          if (index < 6) {
1298            if (c == nsHtml5Tokenizer::CDATA_LSQB[index]) {
1299              appendLongStrBuf(c);
1300            } else {
1301              if (P::reportErrors) {
1302                errBogusComment();
1303              }
1304              reconsume = true;
1305              state = P::transition(mViewSource, NS_HTML5TOKENIZER_BOGUS_COMMENT, reconsume, pos);
1306              NS_HTML5_CONTINUE(stateloop);
1307            }
1308            index++;
1309            continue;
1310          } else {
1311            cstart = pos;
1312            reconsume = true;
1313            state = P::transition(mViewSource, NS_HTML5TOKENIZER_CDATA_SECTION, reconsume, pos);
1314            break;
1315          }
1316        }
1317      }
1318      case NS_HTML5TOKENIZER_CDATA_SECTION: {
1319        for (; ; ) {
1320          if (reconsume) {
1321            reconsume = false;
1322          } else {
1323            if (++pos == endPos) {
1324              NS_HTML5_BREAK(stateloop);
1325            }
1326            c = checkChar(buf, pos);
1327          }
1328          switch(c) {
1329            case ']': {
1330              flushChars(buf, pos);
1331              state = P::transition(mViewSource, NS_HTML5TOKENIZER_CDATA_RSQB, reconsume, pos);
1332              NS_HTML5_BREAK(cdatasectionloop);
1333            }
1334            case '\0': {
1335              emitReplacementCharacter(buf, pos);
1336              continue;
1337            }
1338            case '\r': {
1339              emitCarriageReturn(buf, pos);
1340              NS_HTML5_BREAK(stateloop);
1341            }
1342            case '\n': {
1343              silentLineFeed();
1344            }
1345            default: {
1346              continue;
1347            }
1348          }
1349        }
1350        cdatasectionloop_end: ;
1351      }
1352      case NS_HTML5TOKENIZER_CDATA_RSQB: {
1353        for (; ; ) {
1354          if (++pos == endPos) {
1355            NS_HTML5_BREAK(stateloop);
1356          }
1357          c = checkChar(buf, pos);
1358          switch(c) {
1359            case ']': {
1360              state = P::transition(mViewSource, NS_HTML5TOKENIZER_CDATA_RSQB_RSQB, reconsume, pos);
1361              NS_HTML5_BREAK(cdatarsqb);
1362            }
1363            default: {
1364              tokenHandler->characters(nsHtml5Tokenizer::RSQB_RSQB, 0, 1);
1365              cstart = pos;
1366              reconsume = true;
1367              state = P::transition(mViewSource, NS_HTML5TOKENIZER_CDATA_SECTION, reconsume, pos);
1368              NS_HTML5_CONTINUE(stateloop);
1369            }
1370          }
1371        }
1372        cdatarsqb_end: ;
1373      }
1374      case NS_HTML5TOKENIZER_CDATA_RSQB_RSQB: {
1375        if (++pos == endPos) {
1376          NS_HTML5_BREAK(stateloop);
1377        }
1378        c = checkChar(buf, pos);
1379        switch(c) {
1380          case '>': {
1381            cstart = pos + 1;
1382            state = P::transition(mViewSource, NS_HTML5TOKENIZER_DATA, reconsume, pos);
1383            NS_HTML5_CONTINUE(stateloop);
1384          }
1385          default: {
1386            tokenHandler->characters(nsHtml5Tokenizer::RSQB_RSQB, 0, 2);
1387            cstart = pos;
1388            reconsume = true;
1389            state = P::transition(mViewSource, NS_HTML5TOKENIZER_CDATA_SECTION, reconsume, pos);
1390            NS_HTML5_CONTINUE(stateloop);
1391          }
1392        }
1393      }
1394      case NS_HTML5TOKENIZER_ATTRIBUTE_VALUE_SINGLE_QUOTED: {
1395        for (; ; ) {
1396          if (reconsume) {
1397            reconsume = false;
1398          } else {
1399            if (++pos == endPos) {
1400              NS_HTML5_BREAK(stateloop);
1401            }
1402            c = checkChar(buf, pos);
1403          }
1404          switch(c) {
1405            case '\'': {
1406              addAttributeWithValue();
1407              state = P::transition(mViewSource, NS_HTML5TOKENIZER_AFTER_ATTRIBUTE_VALUE_QUOTED, reconsume, pos);
1408              NS_HTML5_CONTINUE(stateloop);
1409            }
1410            case '&': {
1411              clearStrBufAndAppend(c);
1412              setAdditionalAndRememberAmpersandLocation('\'');
1413              returnState = state;
1414              state = P::transition(mViewSource, NS_HTML5TOKENIZER_CONSUME_CHARACTER_REFERENCE, reconsume, pos);
1415              NS_HTML5_BREAK(attributevaluesinglequotedloop);
1416            }
1417            case '\r': {
1418              appendLongStrBufCarriageReturn();
1419              NS_HTML5_BREAK(stateloop);
1420            }
1421            case '\n': {
1422              appendLongStrBufLineFeed();
1423              continue;
1424            }
1425            case '\0': {
1426              c = 0xfffd;
1427            }
1428            default: {
1429              appendLongStrBuf(c);
1430              continue;
1431            }
1432          }
1433        }
1434        attributevaluesinglequotedloop_end: ;
1435      }
1436      case NS_HTML5TOKENIZER_CONSUME_CHARACTER_REFERENCE: {
1437        if (++pos == endPos) {
1438          NS_HTML5_BREAK(stateloop);
1439        }
1440        c = checkChar(buf, pos);
1441        if (c == '\0') {
1442          NS_HTML5_BREAK(stateloop);
1443        }
1444        switch(c) {
1445          case ' ':
1446          case '\t':
1447          case '\n':
1448          case '\r':
1449          case '\f':
1450          case '<':
1451          case '&': {
1452            emitOrAppendStrBuf(returnState);
1453            if (!(returnState & NS_HTML5TOKENIZER_DATA_AND_RCDATA_MASK)) {
1454              cstart = pos;
1455            }
1456            reconsume = true;
1457            state = P::transition(mViewSource, returnState, reconsume, pos);
1458            NS_HTML5_CONTINUE(stateloop);
1459          }
1460          case '#': {
1461            appendStrBuf('#');
1462            state = P::transition(mViewSource, NS_HTML5TOKENIZER_CONSUME_NCR, reconsume, pos);
1463            NS_HTML5_CONTINUE(stateloop);
1464          }
1465          default: {
1466            if (c == additional) {
1467              emitOrAppendStrBuf(returnState);
1468              reconsume = true;
1469              state = P::transition(mViewSource, returnState, reconsume, pos);
1470              NS_HTML5_CONTINUE(stateloop);
1471            }
1472            if (c >= 'a' && c <= 'z') {
1473              firstCharKey = c - 'a' + 26;
1474            } else if (c >= 'A' && c <= 'Z') {
1475              firstCharKey = c - 'A';
1476            } else {
1477              if (P::reportErrors) {
1478                errNoNamedCharacterMatch();
1479              }
1480              emitOrAppendStrBuf(returnState);
1481              if (!(returnState & NS_HTML5TOKENIZER_DATA_AND_RCDATA_MASK)) {
1482                cstart = pos;
1483              }
1484              reconsume = true;
1485              state = P::transition(mViewSource, returnState, reconsume, pos);
1486              NS_HTML5_CONTINUE(stateloop);
1487            }
1488            appendStrBuf(c);
1489            state = P::transition(mViewSource, NS_HTML5TOKENIZER_CHARACTER_REFERENCE_HILO_LOOKUP, reconsume, pos);
1490          }
1491        }
1492      }
1493      case NS_HTML5TOKENIZER_CHARACTER_REFERENCE_HILO_LOOKUP: {
1494        {
1495          if (++pos == endPos) {
1496            NS_HTML5_BREAK(stateloop);
1497          }
1498          c = checkChar(buf, pos);
1499          if (c == '\0') {
1500            NS_HTML5_BREAK(stateloop);
1501          }
1502          PRInt32 hilo = 0;
1503          if (c <= 'z') {
1504            const PRInt32* row = nsHtml5NamedCharactersAcce

Large files files are truncated, but you can click here to view the full file