2 * Copyright (c) 2007 Henri Sivonen
3 * Copyright (c) 2008-2010 Mozilla Foundation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
26 * Please edit MetaScanner.java instead and regenerate.
29 #define nsHtml5MetaScanner_cpp__
33 #include "nsHtml5AtomTable.h"
35 #include "nsINameSpaceManager.h"
36 #include "nsIContent.h"
37 #include "nsIDocument.h"
38 #include "nsTraceRefcnt.h"
40 #include "nsHtml5DocumentMode.h"
41 #include "nsHtml5ArrayCopy.h"
42 #include "nsHtml5NamedCharacters.h"
43 #include "nsHtml5NamedCharactersAccel.h"
44 #include "nsHtml5Atoms.h"
45 #include "nsHtml5ByteReadable.h"
46 #include "nsIUnicodeDecoder.h"
47 #include "nsAHtml5TreeBuilderState.h"
48 #include "nsHtml5Macros.h"
50 #include "nsHtml5Tokenizer.h"
51 #include "nsHtml5TreeBuilder.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"
60 #include "nsHtml5MetaScanner.h"
63 nsHtml5MetaScanner::stateLoop(PRInt32 state
)
66 PRBool reconsume
= PR_FALSE
;
67 stateloop
: for (; ; ) {
69 case NS_HTML5META_SCANNER_DATA
: {
78 NS_HTML5_BREAK(stateloop
);
81 state
= NS_HTML5META_SCANNER_TAG_OPEN
;
82 NS_HTML5_BREAK(dataloop
);
91 case NS_HTML5META_SCANNER_TAG_OPEN
: {
96 NS_HTML5_BREAK(stateloop
);
100 metaState
= NS_HTML5META_SCANNER_M
;
101 state
= NS_HTML5META_SCANNER_TAG_NAME
;
102 NS_HTML5_BREAK(tagopenloop
);
105 state
= NS_HTML5META_SCANNER_MARKUP_DECLARATION_OPEN
;
106 NS_HTML5_CONTINUE(stateloop
);
110 state
= NS_HTML5META_SCANNER_SCAN_UNTIL_GT
;
111 NS_HTML5_CONTINUE(stateloop
);
114 state
= NS_HTML5META_SCANNER_DATA
;
115 NS_HTML5_CONTINUE(stateloop
);
118 if ((c
>= 'A' && c
<= 'Z') || (c
>= 'a' && c
<= 'z')) {
119 metaState
= NS_HTML5META_SCANNER_NO
;
120 state
= NS_HTML5META_SCANNER_TAG_NAME
;
121 NS_HTML5_BREAK(tagopenloop
);
123 state
= NS_HTML5META_SCANNER_DATA
;
125 NS_HTML5_CONTINUE(stateloop
);
131 case NS_HTML5META_SCANNER_TAG_NAME
: {
136 NS_HTML5_BREAK(stateloop
);
142 state
= NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME
;
143 NS_HTML5_BREAK(tagnameloop
);
146 state
= NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG
;
147 NS_HTML5_CONTINUE(stateloop
);
150 state
= NS_HTML5META_SCANNER_DATA
;
151 NS_HTML5_CONTINUE(stateloop
);
155 if (metaState
== NS_HTML5META_SCANNER_M
) {
156 metaState
= NS_HTML5META_SCANNER_E
;
158 metaState
= NS_HTML5META_SCANNER_NO
;
164 if (metaState
== NS_HTML5META_SCANNER_E
) {
165 metaState
= NS_HTML5META_SCANNER_T
;
167 metaState
= NS_HTML5META_SCANNER_NO
;
173 if (metaState
== NS_HTML5META_SCANNER_T
) {
174 metaState
= NS_HTML5META_SCANNER_A
;
176 metaState
= NS_HTML5META_SCANNER_NO
;
181 metaState
= NS_HTML5META_SCANNER_NO
;
188 case NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME
: {
191 reconsume
= PR_FALSE
;
197 NS_HTML5_BREAK(stateloop
);
206 state
= NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG
;
207 NS_HTML5_CONTINUE(stateloop
);
210 state
= NS_HTML5META_SCANNER_DATA
;
211 NS_HTML5_CONTINUE(stateloop
);
217 state
= NS_HTML5META_SCANNER_ATTRIBUTE_NAME
;
218 NS_HTML5_BREAK(beforeattributenameloop
);
223 state
= NS_HTML5META_SCANNER_ATTRIBUTE_NAME
;
224 NS_HTML5_BREAK(beforeattributenameloop
);
228 beforeattributenameloop_end
: ;
230 case NS_HTML5META_SCANNER_ATTRIBUTE_NAME
: {
235 NS_HTML5_BREAK(stateloop
);
241 state
= NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_NAME
;
242 NS_HTML5_CONTINUE(stateloop
);
245 state
= NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG
;
246 NS_HTML5_CONTINUE(stateloop
);
250 state
= NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_VALUE
;
251 NS_HTML5_BREAK(attributenameloop
);
254 state
= NS_HTML5META_SCANNER_DATA
;
255 NS_HTML5_CONTINUE(stateloop
);
258 if (metaState
== NS_HTML5META_SCANNER_A
) {
259 if (c
>= 'A' && c
<= 'Z') {
262 if (contentIndex
== 6) {
264 } else if (contentIndex
> -1 && contentIndex
< 6 && (c
== CONTENT
[contentIndex
+ 1])) {
267 if (charsetIndex
== 6) {
269 } else if (charsetIndex
> -1 && charsetIndex
< 6 && (c
== CHARSET
[charsetIndex
+ 1])) {
277 attributenameloop_end
: ;
279 case NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_VALUE
: {
284 NS_HTML5_BREAK(stateloop
);
293 state
= NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_DOUBLE_QUOTED
;
294 NS_HTML5_BREAK(beforeattributevalueloop
);
297 state
= NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_SINGLE_QUOTED
;
298 NS_HTML5_CONTINUE(stateloop
);
301 state
= NS_HTML5META_SCANNER_DATA
;
302 NS_HTML5_CONTINUE(stateloop
);
305 if (charsetIndex
== 6 || contentIndex
== 6) {
308 state
= NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_UNQUOTED
;
309 NS_HTML5_CONTINUE(stateloop
);
313 beforeattributevalueloop_end
: ;
315 case NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_DOUBLE_QUOTED
: {
318 reconsume
= PR_FALSE
;
324 NS_HTML5_BREAK(stateloop
);
328 NS_HTML5_BREAK(stateloop
);
330 state
= NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_VALUE_QUOTED
;
331 NS_HTML5_BREAK(attributevaluedoublequotedloop
);
334 if (metaState
== NS_HTML5META_SCANNER_A
&& (contentIndex
== 6 || charsetIndex
== 6)) {
341 attributevaluedoublequotedloop_end
: ;
343 case NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_VALUE_QUOTED
: {
348 NS_HTML5_BREAK(stateloop
);
354 state
= NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME
;
355 NS_HTML5_CONTINUE(stateloop
);
358 state
= NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG
;
359 NS_HTML5_BREAK(afterattributevaluequotedloop
);
362 state
= NS_HTML5META_SCANNER_DATA
;
363 NS_HTML5_CONTINUE(stateloop
);
366 state
= NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME
;
368 NS_HTML5_CONTINUE(stateloop
);
372 afterattributevaluequotedloop_end
: ;
374 case NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG
: {
378 NS_HTML5_BREAK(stateloop
);
381 state
= NS_HTML5META_SCANNER_DATA
;
382 NS_HTML5_CONTINUE(stateloop
);
385 state
= NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME
;
387 NS_HTML5_CONTINUE(stateloop
);
391 case NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_UNQUOTED
: {
394 reconsume
= PR_FALSE
;
400 NS_HTML5_BREAK(stateloop
);
407 NS_HTML5_BREAK(stateloop
);
409 state
= NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME
;
410 NS_HTML5_CONTINUE(stateloop
);
414 NS_HTML5_BREAK(stateloop
);
416 state
= NS_HTML5META_SCANNER_DATA
;
417 NS_HTML5_CONTINUE(stateloop
);
420 if (metaState
== NS_HTML5META_SCANNER_A
&& (contentIndex
== 6 || charsetIndex
== 6)) {
428 case NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_NAME
: {
433 NS_HTML5_BREAK(stateloop
);
443 NS_HTML5_BREAK(stateloop
);
445 state
= NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG
;
446 NS_HTML5_CONTINUE(stateloop
);
449 state
= NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_VALUE
;
450 NS_HTML5_CONTINUE(stateloop
);
454 NS_HTML5_BREAK(stateloop
);
456 state
= NS_HTML5META_SCANNER_DATA
;
457 NS_HTML5_CONTINUE(stateloop
);
463 state
= NS_HTML5META_SCANNER_ATTRIBUTE_NAME
;
464 NS_HTML5_CONTINUE(stateloop
);
469 state
= NS_HTML5META_SCANNER_ATTRIBUTE_NAME
;
470 NS_HTML5_CONTINUE(stateloop
);
475 case NS_HTML5META_SCANNER_MARKUP_DECLARATION_OPEN
: {
480 NS_HTML5_BREAK(stateloop
);
483 state
= NS_HTML5META_SCANNER_MARKUP_DECLARATION_HYPHEN
;
484 NS_HTML5_BREAK(markupdeclarationopenloop
);
487 state
= NS_HTML5META_SCANNER_SCAN_UNTIL_GT
;
489 NS_HTML5_CONTINUE(stateloop
);
493 markupdeclarationopenloop_end
: ;
495 case NS_HTML5META_SCANNER_MARKUP_DECLARATION_HYPHEN
: {
500 NS_HTML5_BREAK(stateloop
);
503 state
= NS_HTML5META_SCANNER_COMMENT_START
;
504 NS_HTML5_BREAK(markupdeclarationhyphenloop
);
507 state
= NS_HTML5META_SCANNER_SCAN_UNTIL_GT
;
509 NS_HTML5_CONTINUE(stateloop
);
513 markupdeclarationhyphenloop_end
: ;
515 case NS_HTML5META_SCANNER_COMMENT_START
: {
520 NS_HTML5_BREAK(stateloop
);
523 state
= NS_HTML5META_SCANNER_COMMENT_START_DASH
;
524 NS_HTML5_CONTINUE(stateloop
);
527 state
= NS_HTML5META_SCANNER_DATA
;
528 NS_HTML5_CONTINUE(stateloop
);
531 state
= NS_HTML5META_SCANNER_COMMENT
;
532 NS_HTML5_BREAK(commentstartloop
);
536 commentstartloop_end
: ;
538 case NS_HTML5META_SCANNER_COMMENT
: {
543 NS_HTML5_BREAK(stateloop
);
546 state
= NS_HTML5META_SCANNER_COMMENT_END_DASH
;
547 NS_HTML5_BREAK(commentloop
);
556 case NS_HTML5META_SCANNER_COMMENT_END_DASH
: {
561 NS_HTML5_BREAK(stateloop
);
564 state
= NS_HTML5META_SCANNER_COMMENT_END
;
565 NS_HTML5_BREAK(commentenddashloop
);
568 state
= NS_HTML5META_SCANNER_COMMENT
;
569 NS_HTML5_CONTINUE(stateloop
);
573 commentenddashloop_end
: ;
575 case NS_HTML5META_SCANNER_COMMENT_END
: {
580 NS_HTML5_BREAK(stateloop
);
583 state
= NS_HTML5META_SCANNER_DATA
;
584 NS_HTML5_CONTINUE(stateloop
);
590 state
= NS_HTML5META_SCANNER_COMMENT
;
591 NS_HTML5_CONTINUE(stateloop
);
596 case NS_HTML5META_SCANNER_COMMENT_START_DASH
: {
600 NS_HTML5_BREAK(stateloop
);
603 state
= NS_HTML5META_SCANNER_COMMENT_END
;
604 NS_HTML5_CONTINUE(stateloop
);
607 state
= NS_HTML5META_SCANNER_DATA
;
608 NS_HTML5_CONTINUE(stateloop
);
611 state
= NS_HTML5META_SCANNER_COMMENT
;
612 NS_HTML5_CONTINUE(stateloop
);
616 case NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_SINGLE_QUOTED
: {
619 reconsume
= PR_FALSE
;
625 NS_HTML5_BREAK(stateloop
);
629 NS_HTML5_BREAK(stateloop
);
631 state
= NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_VALUE_QUOTED
;
632 NS_HTML5_CONTINUE(stateloop
);
635 if (metaState
== NS_HTML5META_SCANNER_A
&& (contentIndex
== 6 || charsetIndex
== 6)) {
643 case NS_HTML5META_SCANNER_SCAN_UNTIL_GT
: {
646 reconsume
= PR_FALSE
;
652 NS_HTML5_BREAK(stateloop
);
655 state
= NS_HTML5META_SCANNER_DATA
;
656 NS_HTML5_CONTINUE(stateloop
);
671 nsHtml5MetaScanner::addToBuffer(PRInt32 c
)
673 if (strBufLen
== strBuf
.length
) {
674 jArray
<PRUnichar
,PRInt32
> newBuf
= jArray
<PRUnichar
,PRInt32
>(strBuf
.length
+ (strBuf
.length
<< 1));
675 nsHtml5ArrayCopy::arraycopy(strBuf
, newBuf
, strBuf
.length
);
679 strBuf
[strBufLen
++] = (PRUnichar
) c
;
683 nsHtml5MetaScanner::tryCharset()
685 if (metaState
!= NS_HTML5META_SCANNER_A
|| !(contentIndex
== 6 || charsetIndex
== 6)) {
688 nsString
* attVal
= nsHtml5Portability::newStringFromBuffer(strBuf
, 0, strBufLen
);
689 nsString
* candidateEncoding
;
690 if (contentIndex
== 6) {
691 candidateEncoding
= nsHtml5TreeBuilder::extractCharsetFromContent(attVal
);
692 nsHtml5Portability::releaseString(attVal
);
694 candidateEncoding
= attVal
;
696 if (!candidateEncoding
) {
699 PRBool success
= tryCharset(candidateEncoding
);
700 nsHtml5Portability::releaseString(candidateEncoding
);
707 nsHtml5MetaScanner::initializeStatics()
712 nsHtml5MetaScanner::releaseStatics()
717 #include "nsHtml5MetaScannerCppSupplement.h"