/parser/html/nsHtml5Tokenizer.cpp

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

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