Bug 601299: Find RegExpStatics in cx->globalObject if necessary. (r=mrbkap)
[mozilla-central.git] / parser / html / nsHtml5MetaScanner.cpp
blob8e8d47fdd2aaece5d03904210b860f32356f7c2f
1 /*
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__
31 #include "prtypes.h"
32 #include "nsIAtom.h"
33 #include "nsHtml5AtomTable.h"
34 #include "nsString.h"
35 #include "nsINameSpaceManager.h"
36 #include "nsIContent.h"
37 #include "nsIDocument.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 "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"
62 void
63 nsHtml5MetaScanner::stateLoop(PRInt32 state)
65 PRInt32 c = -1;
66 PRBool reconsume = PR_FALSE;
67 stateloop: for (; ; ) {
68 switch(state) {
69 case NS_HTML5META_SCANNER_DATA: {
70 for (; ; ) {
71 if (reconsume) {
72 reconsume = PR_FALSE;
73 } else {
74 c = read();
76 switch(c) {
77 case -1: {
78 NS_HTML5_BREAK(stateloop);
80 case '<': {
81 state = NS_HTML5META_SCANNER_TAG_OPEN;
82 NS_HTML5_BREAK(dataloop);
84 default: {
85 continue;
89 dataloop_end: ;
91 case NS_HTML5META_SCANNER_TAG_OPEN: {
92 for (; ; ) {
93 c = read();
94 switch(c) {
95 case -1: {
96 NS_HTML5_BREAK(stateloop);
98 case 'm':
99 case 'M': {
100 metaState = NS_HTML5META_SCANNER_M;
101 state = NS_HTML5META_SCANNER_TAG_NAME;
102 NS_HTML5_BREAK(tagopenloop);
104 case '!': {
105 state = NS_HTML5META_SCANNER_MARKUP_DECLARATION_OPEN;
106 NS_HTML5_CONTINUE(stateloop);
108 case '\?':
109 case '/': {
110 state = NS_HTML5META_SCANNER_SCAN_UNTIL_GT;
111 NS_HTML5_CONTINUE(stateloop);
113 case '>': {
114 state = NS_HTML5META_SCANNER_DATA;
115 NS_HTML5_CONTINUE(stateloop);
117 default: {
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;
124 reconsume = PR_TRUE;
125 NS_HTML5_CONTINUE(stateloop);
129 tagopenloop_end: ;
131 case NS_HTML5META_SCANNER_TAG_NAME: {
132 for (; ; ) {
133 c = read();
134 switch(c) {
135 case -1: {
136 NS_HTML5_BREAK(stateloop);
138 case ' ':
139 case '\t':
140 case '\n':
141 case '\f': {
142 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME;
143 NS_HTML5_BREAK(tagnameloop);
145 case '/': {
146 state = NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG;
147 NS_HTML5_CONTINUE(stateloop);
149 case '>': {
150 state = NS_HTML5META_SCANNER_DATA;
151 NS_HTML5_CONTINUE(stateloop);
153 case 'e':
154 case 'E': {
155 if (metaState == NS_HTML5META_SCANNER_M) {
156 metaState = NS_HTML5META_SCANNER_E;
157 } else {
158 metaState = NS_HTML5META_SCANNER_NO;
160 continue;
162 case 't':
163 case 'T': {
164 if (metaState == NS_HTML5META_SCANNER_E) {
165 metaState = NS_HTML5META_SCANNER_T;
166 } else {
167 metaState = NS_HTML5META_SCANNER_NO;
169 continue;
171 case 'a':
172 case 'A': {
173 if (metaState == NS_HTML5META_SCANNER_T) {
174 metaState = NS_HTML5META_SCANNER_A;
175 } else {
176 metaState = NS_HTML5META_SCANNER_NO;
178 continue;
180 default: {
181 metaState = NS_HTML5META_SCANNER_NO;
182 continue;
186 tagnameloop_end: ;
188 case NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME: {
189 for (; ; ) {
190 if (reconsume) {
191 reconsume = PR_FALSE;
192 } else {
193 c = read();
195 switch(c) {
196 case -1: {
197 NS_HTML5_BREAK(stateloop);
199 case ' ':
200 case '\t':
201 case '\n':
202 case '\f': {
203 continue;
205 case '/': {
206 state = NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG;
207 NS_HTML5_CONTINUE(stateloop);
209 case '>': {
210 state = NS_HTML5META_SCANNER_DATA;
211 NS_HTML5_CONTINUE(stateloop);
213 case 'c':
214 case 'C': {
215 contentIndex = 0;
216 charsetIndex = 0;
217 state = NS_HTML5META_SCANNER_ATTRIBUTE_NAME;
218 NS_HTML5_BREAK(beforeattributenameloop);
220 default: {
221 contentIndex = -1;
222 charsetIndex = -1;
223 state = NS_HTML5META_SCANNER_ATTRIBUTE_NAME;
224 NS_HTML5_BREAK(beforeattributenameloop);
228 beforeattributenameloop_end: ;
230 case NS_HTML5META_SCANNER_ATTRIBUTE_NAME: {
231 for (; ; ) {
232 c = read();
233 switch(c) {
234 case -1: {
235 NS_HTML5_BREAK(stateloop);
237 case ' ':
238 case '\t':
239 case '\n':
240 case '\f': {
241 state = NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_NAME;
242 NS_HTML5_CONTINUE(stateloop);
244 case '/': {
245 state = NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG;
246 NS_HTML5_CONTINUE(stateloop);
248 case '=': {
249 strBufLen = 0;
250 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_VALUE;
251 NS_HTML5_BREAK(attributenameloop);
253 case '>': {
254 state = NS_HTML5META_SCANNER_DATA;
255 NS_HTML5_CONTINUE(stateloop);
257 default: {
258 if (metaState == NS_HTML5META_SCANNER_A) {
259 if (c >= 'A' && c <= 'Z') {
260 c += 0x20;
262 if (contentIndex == 6) {
263 contentIndex = -1;
264 } else if (contentIndex > -1 && contentIndex < 6 && (c == CONTENT[contentIndex + 1])) {
265 contentIndex++;
267 if (charsetIndex == 6) {
268 charsetIndex = -1;
269 } else if (charsetIndex > -1 && charsetIndex < 6 && (c == CHARSET[charsetIndex + 1])) {
270 charsetIndex++;
273 continue;
277 attributenameloop_end: ;
279 case NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_VALUE: {
280 for (; ; ) {
281 c = read();
282 switch(c) {
283 case -1: {
284 NS_HTML5_BREAK(stateloop);
286 case ' ':
287 case '\t':
288 case '\n':
289 case '\f': {
290 continue;
292 case '\"': {
293 state = NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_DOUBLE_QUOTED;
294 NS_HTML5_BREAK(beforeattributevalueloop);
296 case '\'': {
297 state = NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_SINGLE_QUOTED;
298 NS_HTML5_CONTINUE(stateloop);
300 case '>': {
301 state = NS_HTML5META_SCANNER_DATA;
302 NS_HTML5_CONTINUE(stateloop);
304 default: {
305 if (charsetIndex == 6 || contentIndex == 6) {
306 addToBuffer(c);
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: {
316 for (; ; ) {
317 if (reconsume) {
318 reconsume = PR_FALSE;
319 } else {
320 c = read();
322 switch(c) {
323 case -1: {
324 NS_HTML5_BREAK(stateloop);
326 case '\"': {
327 if (tryCharset()) {
328 NS_HTML5_BREAK(stateloop);
330 state = NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_VALUE_QUOTED;
331 NS_HTML5_BREAK(attributevaluedoublequotedloop);
333 default: {
334 if (metaState == NS_HTML5META_SCANNER_A && (contentIndex == 6 || charsetIndex == 6)) {
335 addToBuffer(c);
337 continue;
341 attributevaluedoublequotedloop_end: ;
343 case NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_VALUE_QUOTED: {
344 for (; ; ) {
345 c = read();
346 switch(c) {
347 case -1: {
348 NS_HTML5_BREAK(stateloop);
350 case ' ':
351 case '\t':
352 case '\n':
353 case '\f': {
354 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME;
355 NS_HTML5_CONTINUE(stateloop);
357 case '/': {
358 state = NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG;
359 NS_HTML5_BREAK(afterattributevaluequotedloop);
361 case '>': {
362 state = NS_HTML5META_SCANNER_DATA;
363 NS_HTML5_CONTINUE(stateloop);
365 default: {
366 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME;
367 reconsume = PR_TRUE;
368 NS_HTML5_CONTINUE(stateloop);
372 afterattributevaluequotedloop_end: ;
374 case NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG: {
375 c = read();
376 switch(c) {
377 case -1: {
378 NS_HTML5_BREAK(stateloop);
380 case '>': {
381 state = NS_HTML5META_SCANNER_DATA;
382 NS_HTML5_CONTINUE(stateloop);
384 default: {
385 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME;
386 reconsume = PR_TRUE;
387 NS_HTML5_CONTINUE(stateloop);
391 case NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_UNQUOTED: {
392 for (; ; ) {
393 if (reconsume) {
394 reconsume = PR_FALSE;
395 } else {
396 c = read();
398 switch(c) {
399 case -1: {
400 NS_HTML5_BREAK(stateloop);
402 case ' ':
403 case '\t':
404 case '\n':
405 case '\f': {
406 if (tryCharset()) {
407 NS_HTML5_BREAK(stateloop);
409 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME;
410 NS_HTML5_CONTINUE(stateloop);
412 case '>': {
413 if (tryCharset()) {
414 NS_HTML5_BREAK(stateloop);
416 state = NS_HTML5META_SCANNER_DATA;
417 NS_HTML5_CONTINUE(stateloop);
419 default: {
420 if (metaState == NS_HTML5META_SCANNER_A && (contentIndex == 6 || charsetIndex == 6)) {
421 addToBuffer(c);
423 continue;
428 case NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_NAME: {
429 for (; ; ) {
430 c = read();
431 switch(c) {
432 case -1: {
433 NS_HTML5_BREAK(stateloop);
435 case ' ':
436 case '\t':
437 case '\n':
438 case '\f': {
439 continue;
441 case '/': {
442 if (tryCharset()) {
443 NS_HTML5_BREAK(stateloop);
445 state = NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG;
446 NS_HTML5_CONTINUE(stateloop);
448 case '=': {
449 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_VALUE;
450 NS_HTML5_CONTINUE(stateloop);
452 case '>': {
453 if (tryCharset()) {
454 NS_HTML5_BREAK(stateloop);
456 state = NS_HTML5META_SCANNER_DATA;
457 NS_HTML5_CONTINUE(stateloop);
459 case 'c':
460 case 'C': {
461 contentIndex = 0;
462 charsetIndex = 0;
463 state = NS_HTML5META_SCANNER_ATTRIBUTE_NAME;
464 NS_HTML5_CONTINUE(stateloop);
466 default: {
467 contentIndex = -1;
468 charsetIndex = -1;
469 state = NS_HTML5META_SCANNER_ATTRIBUTE_NAME;
470 NS_HTML5_CONTINUE(stateloop);
475 case NS_HTML5META_SCANNER_MARKUP_DECLARATION_OPEN: {
476 for (; ; ) {
477 c = read();
478 switch(c) {
479 case -1: {
480 NS_HTML5_BREAK(stateloop);
482 case '-': {
483 state = NS_HTML5META_SCANNER_MARKUP_DECLARATION_HYPHEN;
484 NS_HTML5_BREAK(markupdeclarationopenloop);
486 default: {
487 state = NS_HTML5META_SCANNER_SCAN_UNTIL_GT;
488 reconsume = PR_TRUE;
489 NS_HTML5_CONTINUE(stateloop);
493 markupdeclarationopenloop_end: ;
495 case NS_HTML5META_SCANNER_MARKUP_DECLARATION_HYPHEN: {
496 for (; ; ) {
497 c = read();
498 switch(c) {
499 case -1: {
500 NS_HTML5_BREAK(stateloop);
502 case '-': {
503 state = NS_HTML5META_SCANNER_COMMENT_START;
504 NS_HTML5_BREAK(markupdeclarationhyphenloop);
506 default: {
507 state = NS_HTML5META_SCANNER_SCAN_UNTIL_GT;
508 reconsume = PR_TRUE;
509 NS_HTML5_CONTINUE(stateloop);
513 markupdeclarationhyphenloop_end: ;
515 case NS_HTML5META_SCANNER_COMMENT_START: {
516 for (; ; ) {
517 c = read();
518 switch(c) {
519 case -1: {
520 NS_HTML5_BREAK(stateloop);
522 case '-': {
523 state = NS_HTML5META_SCANNER_COMMENT_START_DASH;
524 NS_HTML5_CONTINUE(stateloop);
526 case '>': {
527 state = NS_HTML5META_SCANNER_DATA;
528 NS_HTML5_CONTINUE(stateloop);
530 default: {
531 state = NS_HTML5META_SCANNER_COMMENT;
532 NS_HTML5_BREAK(commentstartloop);
536 commentstartloop_end: ;
538 case NS_HTML5META_SCANNER_COMMENT: {
539 for (; ; ) {
540 c = read();
541 switch(c) {
542 case -1: {
543 NS_HTML5_BREAK(stateloop);
545 case '-': {
546 state = NS_HTML5META_SCANNER_COMMENT_END_DASH;
547 NS_HTML5_BREAK(commentloop);
549 default: {
550 continue;
554 commentloop_end: ;
556 case NS_HTML5META_SCANNER_COMMENT_END_DASH: {
557 for (; ; ) {
558 c = read();
559 switch(c) {
560 case -1: {
561 NS_HTML5_BREAK(stateloop);
563 case '-': {
564 state = NS_HTML5META_SCANNER_COMMENT_END;
565 NS_HTML5_BREAK(commentenddashloop);
567 default: {
568 state = NS_HTML5META_SCANNER_COMMENT;
569 NS_HTML5_CONTINUE(stateloop);
573 commentenddashloop_end: ;
575 case NS_HTML5META_SCANNER_COMMENT_END: {
576 for (; ; ) {
577 c = read();
578 switch(c) {
579 case -1: {
580 NS_HTML5_BREAK(stateloop);
582 case '>': {
583 state = NS_HTML5META_SCANNER_DATA;
584 NS_HTML5_CONTINUE(stateloop);
586 case '-': {
587 continue;
589 default: {
590 state = NS_HTML5META_SCANNER_COMMENT;
591 NS_HTML5_CONTINUE(stateloop);
596 case NS_HTML5META_SCANNER_COMMENT_START_DASH: {
597 c = read();
598 switch(c) {
599 case -1: {
600 NS_HTML5_BREAK(stateloop);
602 case '-': {
603 state = NS_HTML5META_SCANNER_COMMENT_END;
604 NS_HTML5_CONTINUE(stateloop);
606 case '>': {
607 state = NS_HTML5META_SCANNER_DATA;
608 NS_HTML5_CONTINUE(stateloop);
610 default: {
611 state = NS_HTML5META_SCANNER_COMMENT;
612 NS_HTML5_CONTINUE(stateloop);
616 case NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_SINGLE_QUOTED: {
617 for (; ; ) {
618 if (reconsume) {
619 reconsume = PR_FALSE;
620 } else {
621 c = read();
623 switch(c) {
624 case -1: {
625 NS_HTML5_BREAK(stateloop);
627 case '\'': {
628 if (tryCharset()) {
629 NS_HTML5_BREAK(stateloop);
631 state = NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_VALUE_QUOTED;
632 NS_HTML5_CONTINUE(stateloop);
634 default: {
635 if (metaState == NS_HTML5META_SCANNER_A && (contentIndex == 6 || charsetIndex == 6)) {
636 addToBuffer(c);
638 continue;
643 case NS_HTML5META_SCANNER_SCAN_UNTIL_GT: {
644 for (; ; ) {
645 if (reconsume) {
646 reconsume = PR_FALSE;
647 } else {
648 c = read();
650 switch(c) {
651 case -1: {
652 NS_HTML5_BREAK(stateloop);
654 case '>': {
655 state = NS_HTML5META_SCANNER_DATA;
656 NS_HTML5_CONTINUE(stateloop);
658 default: {
659 continue;
666 stateloop_end: ;
667 stateSave = state;
670 void
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);
676 strBuf.release();
677 strBuf = newBuf;
679 strBuf[strBufLen++] = (PRUnichar) c;
682 PRBool
683 nsHtml5MetaScanner::tryCharset()
685 if (metaState != NS_HTML5META_SCANNER_A || !(contentIndex == 6 || charsetIndex == 6)) {
686 return PR_FALSE;
688 nsString* attVal = nsHtml5Portability::newStringFromBuffer(strBuf, 0, strBufLen);
689 nsString* candidateEncoding;
690 if (contentIndex == 6) {
691 candidateEncoding = nsHtml5TreeBuilder::extractCharsetFromContent(attVal);
692 nsHtml5Portability::releaseString(attVal);
693 } else {
694 candidateEncoding = attVal;
696 if (!candidateEncoding) {
697 return PR_FALSE;
699 PRBool success = tryCharset(candidateEncoding);
700 nsHtml5Portability::releaseString(candidateEncoding);
701 contentIndex = -1;
702 charsetIndex = -1;
703 return success;
706 void
707 nsHtml5MetaScanner::initializeStatics()
711 void
712 nsHtml5MetaScanner::releaseStatics()
717 #include "nsHtml5MetaScannerCppSupplement.h"