parser/html/nsHtml5MetaScanner.cpp

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /*
michael@0 2 * Copyright (c) 2007 Henri Sivonen
michael@0 3 * Copyright (c) 2008-2010 Mozilla Foundation
michael@0 4 *
michael@0 5 * Permission is hereby granted, free of charge, to any person obtaining a
michael@0 6 * copy of this software and associated documentation files (the "Software"),
michael@0 7 * to deal in the Software without restriction, including without limitation
michael@0 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
michael@0 9 * and/or sell copies of the Software, and to permit persons to whom the
michael@0 10 * Software is furnished to do so, subject to the following conditions:
michael@0 11 *
michael@0 12 * The above copyright notice and this permission notice shall be included in
michael@0 13 * all copies or substantial portions of the Software.
michael@0 14 *
michael@0 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
michael@0 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
michael@0 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
michael@0 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
michael@0 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
michael@0 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
michael@0 21 * DEALINGS IN THE SOFTWARE.
michael@0 22 */
michael@0 23
michael@0 24 /*
michael@0 25 * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
michael@0 26 * Please edit MetaScanner.java instead and regenerate.
michael@0 27 */
michael@0 28
michael@0 29 #define nsHtml5MetaScanner_cpp__
michael@0 30
michael@0 31 #include "nsIAtom.h"
michael@0 32 #include "nsHtml5AtomTable.h"
michael@0 33 #include "nsString.h"
michael@0 34 #include "nsNameSpaceManager.h"
michael@0 35 #include "nsIContent.h"
michael@0 36 #include "nsTraceRefcnt.h"
michael@0 37 #include "jArray.h"
michael@0 38 #include "nsHtml5ArrayCopy.h"
michael@0 39 #include "nsAHtml5TreeBuilderState.h"
michael@0 40 #include "nsHtml5Atoms.h"
michael@0 41 #include "nsHtml5ByteReadable.h"
michael@0 42 #include "nsIUnicodeDecoder.h"
michael@0 43 #include "nsHtml5Macros.h"
michael@0 44 #include "nsIContentHandle.h"
michael@0 45
michael@0 46 #include "nsHtml5Tokenizer.h"
michael@0 47 #include "nsHtml5TreeBuilder.h"
michael@0 48 #include "nsHtml5AttributeName.h"
michael@0 49 #include "nsHtml5ElementName.h"
michael@0 50 #include "nsHtml5HtmlAttributes.h"
michael@0 51 #include "nsHtml5StackNode.h"
michael@0 52 #include "nsHtml5UTF16Buffer.h"
michael@0 53 #include "nsHtml5StateSnapshot.h"
michael@0 54 #include "nsHtml5Portability.h"
michael@0 55
michael@0 56 #include "nsHtml5MetaScanner.h"
michael@0 57
michael@0 58 static char16_t const CHARSET_DATA[] = { 'h', 'a', 'r', 's', 'e', 't' };
michael@0 59 staticJArray<char16_t,int32_t> nsHtml5MetaScanner::CHARSET = { CHARSET_DATA, MOZ_ARRAY_LENGTH(CHARSET_DATA) };
michael@0 60 static char16_t const CONTENT_DATA[] = { 'o', 'n', 't', 'e', 'n', 't' };
michael@0 61 staticJArray<char16_t,int32_t> nsHtml5MetaScanner::CONTENT = { CONTENT_DATA, MOZ_ARRAY_LENGTH(CONTENT_DATA) };
michael@0 62 static char16_t const HTTP_EQUIV_DATA[] = { 't', 't', 'p', '-', 'e', 'q', 'u', 'i', 'v' };
michael@0 63 staticJArray<char16_t,int32_t> nsHtml5MetaScanner::HTTP_EQUIV = { HTTP_EQUIV_DATA, MOZ_ARRAY_LENGTH(HTTP_EQUIV_DATA) };
michael@0 64 static char16_t const CONTENT_TYPE_DATA[] = { 'c', 'o', 'n', 't', 'e', 'n', 't', '-', 't', 'y', 'p', 'e' };
michael@0 65 staticJArray<char16_t,int32_t> nsHtml5MetaScanner::CONTENT_TYPE = { CONTENT_TYPE_DATA, MOZ_ARRAY_LENGTH(CONTENT_TYPE_DATA) };
michael@0 66
michael@0 67 nsHtml5MetaScanner::nsHtml5MetaScanner()
michael@0 68 : readable(nullptr),
michael@0 69 metaState(NS_HTML5META_SCANNER_NO),
michael@0 70 contentIndex(INT32_MAX),
michael@0 71 charsetIndex(INT32_MAX),
michael@0 72 httpEquivIndex(INT32_MAX),
michael@0 73 contentTypeIndex(INT32_MAX),
michael@0 74 stateSave(NS_HTML5META_SCANNER_DATA),
michael@0 75 strBufLen(0),
michael@0 76 strBuf(jArray<char16_t,int32_t>::newJArray(36)),
michael@0 77 content(nullptr),
michael@0 78 charset(nullptr),
michael@0 79 httpEquivState(NS_HTML5META_SCANNER_HTTP_EQUIV_NOT_SEEN)
michael@0 80 {
michael@0 81 MOZ_COUNT_CTOR(nsHtml5MetaScanner);
michael@0 82 }
michael@0 83
michael@0 84
michael@0 85 nsHtml5MetaScanner::~nsHtml5MetaScanner()
michael@0 86 {
michael@0 87 MOZ_COUNT_DTOR(nsHtml5MetaScanner);
michael@0 88 nsHtml5Portability::releaseString(content);
michael@0 89 nsHtml5Portability::releaseString(charset);
michael@0 90 }
michael@0 91
michael@0 92 void
michael@0 93 nsHtml5MetaScanner::stateLoop(int32_t state)
michael@0 94 {
michael@0 95 int32_t c = -1;
michael@0 96 bool reconsume = false;
michael@0 97 stateloop: for (; ; ) {
michael@0 98 switch(state) {
michael@0 99 case NS_HTML5META_SCANNER_DATA: {
michael@0 100 for (; ; ) {
michael@0 101 if (reconsume) {
michael@0 102 reconsume = false;
michael@0 103 } else {
michael@0 104 c = read();
michael@0 105 }
michael@0 106 switch(c) {
michael@0 107 case -1: {
michael@0 108 NS_HTML5_BREAK(stateloop);
michael@0 109 }
michael@0 110 case '<': {
michael@0 111 state = NS_HTML5META_SCANNER_TAG_OPEN;
michael@0 112 NS_HTML5_BREAK(dataloop);
michael@0 113 }
michael@0 114 default: {
michael@0 115 continue;
michael@0 116 }
michael@0 117 }
michael@0 118 }
michael@0 119 dataloop_end: ;
michael@0 120 }
michael@0 121 case NS_HTML5META_SCANNER_TAG_OPEN: {
michael@0 122 for (; ; ) {
michael@0 123 c = read();
michael@0 124 switch(c) {
michael@0 125 case -1: {
michael@0 126 NS_HTML5_BREAK(stateloop);
michael@0 127 }
michael@0 128 case 'm':
michael@0 129 case 'M': {
michael@0 130 metaState = NS_HTML5META_SCANNER_M;
michael@0 131 state = NS_HTML5META_SCANNER_TAG_NAME;
michael@0 132 NS_HTML5_BREAK(tagopenloop);
michael@0 133 }
michael@0 134 case '!': {
michael@0 135 state = NS_HTML5META_SCANNER_MARKUP_DECLARATION_OPEN;
michael@0 136 NS_HTML5_CONTINUE(stateloop);
michael@0 137 }
michael@0 138 case '\?':
michael@0 139 case '/': {
michael@0 140 state = NS_HTML5META_SCANNER_SCAN_UNTIL_GT;
michael@0 141 NS_HTML5_CONTINUE(stateloop);
michael@0 142 }
michael@0 143 case '>': {
michael@0 144 state = NS_HTML5META_SCANNER_DATA;
michael@0 145 NS_HTML5_CONTINUE(stateloop);
michael@0 146 }
michael@0 147 default: {
michael@0 148 if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
michael@0 149 metaState = NS_HTML5META_SCANNER_NO;
michael@0 150 state = NS_HTML5META_SCANNER_TAG_NAME;
michael@0 151 NS_HTML5_BREAK(tagopenloop);
michael@0 152 }
michael@0 153 state = NS_HTML5META_SCANNER_DATA;
michael@0 154 reconsume = true;
michael@0 155 NS_HTML5_CONTINUE(stateloop);
michael@0 156 }
michael@0 157 }
michael@0 158 }
michael@0 159 tagopenloop_end: ;
michael@0 160 }
michael@0 161 case NS_HTML5META_SCANNER_TAG_NAME: {
michael@0 162 for (; ; ) {
michael@0 163 c = read();
michael@0 164 switch(c) {
michael@0 165 case -1: {
michael@0 166 NS_HTML5_BREAK(stateloop);
michael@0 167 }
michael@0 168 case ' ':
michael@0 169 case '\t':
michael@0 170 case '\n':
michael@0 171 case '\f': {
michael@0 172 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME;
michael@0 173 NS_HTML5_BREAK(tagnameloop);
michael@0 174 }
michael@0 175 case '/': {
michael@0 176 state = NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG;
michael@0 177 NS_HTML5_CONTINUE(stateloop);
michael@0 178 }
michael@0 179 case '>': {
michael@0 180 state = NS_HTML5META_SCANNER_DATA;
michael@0 181 NS_HTML5_CONTINUE(stateloop);
michael@0 182 }
michael@0 183 case 'e':
michael@0 184 case 'E': {
michael@0 185 if (metaState == NS_HTML5META_SCANNER_M) {
michael@0 186 metaState = NS_HTML5META_SCANNER_E;
michael@0 187 } else {
michael@0 188 metaState = NS_HTML5META_SCANNER_NO;
michael@0 189 }
michael@0 190 continue;
michael@0 191 }
michael@0 192 case 't':
michael@0 193 case 'T': {
michael@0 194 if (metaState == NS_HTML5META_SCANNER_E) {
michael@0 195 metaState = NS_HTML5META_SCANNER_T;
michael@0 196 } else {
michael@0 197 metaState = NS_HTML5META_SCANNER_NO;
michael@0 198 }
michael@0 199 continue;
michael@0 200 }
michael@0 201 case 'a':
michael@0 202 case 'A': {
michael@0 203 if (metaState == NS_HTML5META_SCANNER_T) {
michael@0 204 metaState = NS_HTML5META_SCANNER_A;
michael@0 205 } else {
michael@0 206 metaState = NS_HTML5META_SCANNER_NO;
michael@0 207 }
michael@0 208 continue;
michael@0 209 }
michael@0 210 default: {
michael@0 211 metaState = NS_HTML5META_SCANNER_NO;
michael@0 212 continue;
michael@0 213 }
michael@0 214 }
michael@0 215 }
michael@0 216 tagnameloop_end: ;
michael@0 217 }
michael@0 218 case NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME: {
michael@0 219 for (; ; ) {
michael@0 220 if (reconsume) {
michael@0 221 reconsume = false;
michael@0 222 } else {
michael@0 223 c = read();
michael@0 224 }
michael@0 225 switch(c) {
michael@0 226 case -1: {
michael@0 227 NS_HTML5_BREAK(stateloop);
michael@0 228 }
michael@0 229 case ' ':
michael@0 230 case '\t':
michael@0 231 case '\n':
michael@0 232 case '\f': {
michael@0 233 continue;
michael@0 234 }
michael@0 235 case '/': {
michael@0 236 state = NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG;
michael@0 237 NS_HTML5_CONTINUE(stateloop);
michael@0 238 }
michael@0 239 case '>': {
michael@0 240 if (handleTag()) {
michael@0 241 NS_HTML5_BREAK(stateloop);
michael@0 242 }
michael@0 243 state = NS_HTML5META_SCANNER_DATA;
michael@0 244 NS_HTML5_CONTINUE(stateloop);
michael@0 245 }
michael@0 246 case 'c':
michael@0 247 case 'C': {
michael@0 248 contentIndex = 0;
michael@0 249 charsetIndex = 0;
michael@0 250 httpEquivIndex = INT32_MAX;
michael@0 251 contentTypeIndex = INT32_MAX;
michael@0 252 state = NS_HTML5META_SCANNER_ATTRIBUTE_NAME;
michael@0 253 NS_HTML5_BREAK(beforeattributenameloop);
michael@0 254 }
michael@0 255 case 'h':
michael@0 256 case 'H': {
michael@0 257 contentIndex = INT32_MAX;
michael@0 258 charsetIndex = INT32_MAX;
michael@0 259 httpEquivIndex = 0;
michael@0 260 contentTypeIndex = INT32_MAX;
michael@0 261 state = NS_HTML5META_SCANNER_ATTRIBUTE_NAME;
michael@0 262 NS_HTML5_BREAK(beforeattributenameloop);
michael@0 263 }
michael@0 264 default: {
michael@0 265 contentIndex = INT32_MAX;
michael@0 266 charsetIndex = INT32_MAX;
michael@0 267 httpEquivIndex = INT32_MAX;
michael@0 268 contentTypeIndex = INT32_MAX;
michael@0 269 state = NS_HTML5META_SCANNER_ATTRIBUTE_NAME;
michael@0 270 NS_HTML5_BREAK(beforeattributenameloop);
michael@0 271 }
michael@0 272 }
michael@0 273 }
michael@0 274 beforeattributenameloop_end: ;
michael@0 275 }
michael@0 276 case NS_HTML5META_SCANNER_ATTRIBUTE_NAME: {
michael@0 277 for (; ; ) {
michael@0 278 c = read();
michael@0 279 switch(c) {
michael@0 280 case -1: {
michael@0 281 NS_HTML5_BREAK(stateloop);
michael@0 282 }
michael@0 283 case ' ':
michael@0 284 case '\t':
michael@0 285 case '\n':
michael@0 286 case '\f': {
michael@0 287 state = NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_NAME;
michael@0 288 NS_HTML5_CONTINUE(stateloop);
michael@0 289 }
michael@0 290 case '/': {
michael@0 291 state = NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG;
michael@0 292 NS_HTML5_CONTINUE(stateloop);
michael@0 293 }
michael@0 294 case '=': {
michael@0 295 strBufLen = 0;
michael@0 296 contentTypeIndex = 0;
michael@0 297 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_VALUE;
michael@0 298 NS_HTML5_BREAK(attributenameloop);
michael@0 299 }
michael@0 300 case '>': {
michael@0 301 if (handleTag()) {
michael@0 302 NS_HTML5_BREAK(stateloop);
michael@0 303 }
michael@0 304 state = NS_HTML5META_SCANNER_DATA;
michael@0 305 NS_HTML5_CONTINUE(stateloop);
michael@0 306 }
michael@0 307 default: {
michael@0 308 if (metaState == NS_HTML5META_SCANNER_A) {
michael@0 309 if (c >= 'A' && c <= 'Z') {
michael@0 310 c += 0x20;
michael@0 311 }
michael@0 312 if (contentIndex < CONTENT.length && c == CONTENT[contentIndex]) {
michael@0 313 ++contentIndex;
michael@0 314 } else {
michael@0 315 contentIndex = INT32_MAX;
michael@0 316 }
michael@0 317 if (charsetIndex < CHARSET.length && c == CHARSET[charsetIndex]) {
michael@0 318 ++charsetIndex;
michael@0 319 } else {
michael@0 320 charsetIndex = INT32_MAX;
michael@0 321 }
michael@0 322 if (httpEquivIndex < HTTP_EQUIV.length && c == HTTP_EQUIV[httpEquivIndex]) {
michael@0 323 ++httpEquivIndex;
michael@0 324 } else {
michael@0 325 httpEquivIndex = INT32_MAX;
michael@0 326 }
michael@0 327 }
michael@0 328 continue;
michael@0 329 }
michael@0 330 }
michael@0 331 }
michael@0 332 attributenameloop_end: ;
michael@0 333 }
michael@0 334 case NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_VALUE: {
michael@0 335 for (; ; ) {
michael@0 336 c = read();
michael@0 337 switch(c) {
michael@0 338 case -1: {
michael@0 339 NS_HTML5_BREAK(stateloop);
michael@0 340 }
michael@0 341 case ' ':
michael@0 342 case '\t':
michael@0 343 case '\n':
michael@0 344 case '\f': {
michael@0 345 continue;
michael@0 346 }
michael@0 347 case '\"': {
michael@0 348 state = NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_DOUBLE_QUOTED;
michael@0 349 NS_HTML5_BREAK(beforeattributevalueloop);
michael@0 350 }
michael@0 351 case '\'': {
michael@0 352 state = NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_SINGLE_QUOTED;
michael@0 353 NS_HTML5_CONTINUE(stateloop);
michael@0 354 }
michael@0 355 case '>': {
michael@0 356 if (handleTag()) {
michael@0 357 NS_HTML5_BREAK(stateloop);
michael@0 358 }
michael@0 359 state = NS_HTML5META_SCANNER_DATA;
michael@0 360 NS_HTML5_CONTINUE(stateloop);
michael@0 361 }
michael@0 362 default: {
michael@0 363 handleCharInAttributeValue(c);
michael@0 364 state = NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_UNQUOTED;
michael@0 365 NS_HTML5_CONTINUE(stateloop);
michael@0 366 }
michael@0 367 }
michael@0 368 }
michael@0 369 beforeattributevalueloop_end: ;
michael@0 370 }
michael@0 371 case NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_DOUBLE_QUOTED: {
michael@0 372 for (; ; ) {
michael@0 373 if (reconsume) {
michael@0 374 reconsume = false;
michael@0 375 } else {
michael@0 376 c = read();
michael@0 377 }
michael@0 378 switch(c) {
michael@0 379 case -1: {
michael@0 380 NS_HTML5_BREAK(stateloop);
michael@0 381 }
michael@0 382 case '\"': {
michael@0 383 handleAttributeValue();
michael@0 384 state = NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_VALUE_QUOTED;
michael@0 385 NS_HTML5_BREAK(attributevaluedoublequotedloop);
michael@0 386 }
michael@0 387 default: {
michael@0 388 handleCharInAttributeValue(c);
michael@0 389 continue;
michael@0 390 }
michael@0 391 }
michael@0 392 }
michael@0 393 attributevaluedoublequotedloop_end: ;
michael@0 394 }
michael@0 395 case NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_VALUE_QUOTED: {
michael@0 396 for (; ; ) {
michael@0 397 c = read();
michael@0 398 switch(c) {
michael@0 399 case -1: {
michael@0 400 NS_HTML5_BREAK(stateloop);
michael@0 401 }
michael@0 402 case ' ':
michael@0 403 case '\t':
michael@0 404 case '\n':
michael@0 405 case '\f': {
michael@0 406 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME;
michael@0 407 NS_HTML5_CONTINUE(stateloop);
michael@0 408 }
michael@0 409 case '/': {
michael@0 410 state = NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG;
michael@0 411 NS_HTML5_BREAK(afterattributevaluequotedloop);
michael@0 412 }
michael@0 413 case '>': {
michael@0 414 if (handleTag()) {
michael@0 415 NS_HTML5_BREAK(stateloop);
michael@0 416 }
michael@0 417 state = NS_HTML5META_SCANNER_DATA;
michael@0 418 NS_HTML5_CONTINUE(stateloop);
michael@0 419 }
michael@0 420 default: {
michael@0 421 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME;
michael@0 422 reconsume = true;
michael@0 423 NS_HTML5_CONTINUE(stateloop);
michael@0 424 }
michael@0 425 }
michael@0 426 }
michael@0 427 afterattributevaluequotedloop_end: ;
michael@0 428 }
michael@0 429 case NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG: {
michael@0 430 c = read();
michael@0 431 switch(c) {
michael@0 432 case -1: {
michael@0 433 NS_HTML5_BREAK(stateloop);
michael@0 434 }
michael@0 435 case '>': {
michael@0 436 if (handleTag()) {
michael@0 437 NS_HTML5_BREAK(stateloop);
michael@0 438 }
michael@0 439 state = NS_HTML5META_SCANNER_DATA;
michael@0 440 NS_HTML5_CONTINUE(stateloop);
michael@0 441 }
michael@0 442 default: {
michael@0 443 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME;
michael@0 444 reconsume = true;
michael@0 445 NS_HTML5_CONTINUE(stateloop);
michael@0 446 }
michael@0 447 }
michael@0 448 }
michael@0 449 case NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_UNQUOTED: {
michael@0 450 for (; ; ) {
michael@0 451 if (reconsume) {
michael@0 452 reconsume = false;
michael@0 453 } else {
michael@0 454 c = read();
michael@0 455 }
michael@0 456 switch(c) {
michael@0 457 case -1: {
michael@0 458 NS_HTML5_BREAK(stateloop);
michael@0 459 }
michael@0 460 case ' ':
michael@0 461 case '\t':
michael@0 462 case '\n':
michael@0 463 case '\f': {
michael@0 464 handleAttributeValue();
michael@0 465 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_NAME;
michael@0 466 NS_HTML5_CONTINUE(stateloop);
michael@0 467 }
michael@0 468 case '>': {
michael@0 469 handleAttributeValue();
michael@0 470 if (handleTag()) {
michael@0 471 NS_HTML5_BREAK(stateloop);
michael@0 472 }
michael@0 473 state = NS_HTML5META_SCANNER_DATA;
michael@0 474 NS_HTML5_CONTINUE(stateloop);
michael@0 475 }
michael@0 476 default: {
michael@0 477 handleCharInAttributeValue(c);
michael@0 478 continue;
michael@0 479 }
michael@0 480 }
michael@0 481 }
michael@0 482 }
michael@0 483 case NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_NAME: {
michael@0 484 for (; ; ) {
michael@0 485 c = read();
michael@0 486 switch(c) {
michael@0 487 case -1: {
michael@0 488 NS_HTML5_BREAK(stateloop);
michael@0 489 }
michael@0 490 case ' ':
michael@0 491 case '\t':
michael@0 492 case '\n':
michael@0 493 case '\f': {
michael@0 494 continue;
michael@0 495 }
michael@0 496 case '/': {
michael@0 497 handleAttributeValue();
michael@0 498 state = NS_HTML5META_SCANNER_SELF_CLOSING_START_TAG;
michael@0 499 NS_HTML5_CONTINUE(stateloop);
michael@0 500 }
michael@0 501 case '=': {
michael@0 502 strBufLen = 0;
michael@0 503 contentTypeIndex = 0;
michael@0 504 state = NS_HTML5META_SCANNER_BEFORE_ATTRIBUTE_VALUE;
michael@0 505 NS_HTML5_CONTINUE(stateloop);
michael@0 506 }
michael@0 507 case '>': {
michael@0 508 handleAttributeValue();
michael@0 509 if (handleTag()) {
michael@0 510 NS_HTML5_BREAK(stateloop);
michael@0 511 }
michael@0 512 state = NS_HTML5META_SCANNER_DATA;
michael@0 513 NS_HTML5_CONTINUE(stateloop);
michael@0 514 }
michael@0 515 case 'c':
michael@0 516 case 'C': {
michael@0 517 contentIndex = 0;
michael@0 518 charsetIndex = 0;
michael@0 519 state = NS_HTML5META_SCANNER_ATTRIBUTE_NAME;
michael@0 520 NS_HTML5_CONTINUE(stateloop);
michael@0 521 }
michael@0 522 default: {
michael@0 523 contentIndex = INT32_MAX;
michael@0 524 charsetIndex = INT32_MAX;
michael@0 525 state = NS_HTML5META_SCANNER_ATTRIBUTE_NAME;
michael@0 526 NS_HTML5_CONTINUE(stateloop);
michael@0 527 }
michael@0 528 }
michael@0 529 }
michael@0 530 }
michael@0 531 case NS_HTML5META_SCANNER_MARKUP_DECLARATION_OPEN: {
michael@0 532 for (; ; ) {
michael@0 533 c = read();
michael@0 534 switch(c) {
michael@0 535 case -1: {
michael@0 536 NS_HTML5_BREAK(stateloop);
michael@0 537 }
michael@0 538 case '-': {
michael@0 539 state = NS_HTML5META_SCANNER_MARKUP_DECLARATION_HYPHEN;
michael@0 540 NS_HTML5_BREAK(markupdeclarationopenloop);
michael@0 541 }
michael@0 542 default: {
michael@0 543 state = NS_HTML5META_SCANNER_SCAN_UNTIL_GT;
michael@0 544 reconsume = true;
michael@0 545 NS_HTML5_CONTINUE(stateloop);
michael@0 546 }
michael@0 547 }
michael@0 548 }
michael@0 549 markupdeclarationopenloop_end: ;
michael@0 550 }
michael@0 551 case NS_HTML5META_SCANNER_MARKUP_DECLARATION_HYPHEN: {
michael@0 552 for (; ; ) {
michael@0 553 c = read();
michael@0 554 switch(c) {
michael@0 555 case -1: {
michael@0 556 NS_HTML5_BREAK(stateloop);
michael@0 557 }
michael@0 558 case '-': {
michael@0 559 state = NS_HTML5META_SCANNER_COMMENT_START;
michael@0 560 NS_HTML5_BREAK(markupdeclarationhyphenloop);
michael@0 561 }
michael@0 562 default: {
michael@0 563 state = NS_HTML5META_SCANNER_SCAN_UNTIL_GT;
michael@0 564 reconsume = true;
michael@0 565 NS_HTML5_CONTINUE(stateloop);
michael@0 566 }
michael@0 567 }
michael@0 568 }
michael@0 569 markupdeclarationhyphenloop_end: ;
michael@0 570 }
michael@0 571 case NS_HTML5META_SCANNER_COMMENT_START: {
michael@0 572 for (; ; ) {
michael@0 573 c = read();
michael@0 574 switch(c) {
michael@0 575 case -1: {
michael@0 576 NS_HTML5_BREAK(stateloop);
michael@0 577 }
michael@0 578 case '-': {
michael@0 579 state = NS_HTML5META_SCANNER_COMMENT_START_DASH;
michael@0 580 NS_HTML5_CONTINUE(stateloop);
michael@0 581 }
michael@0 582 case '>': {
michael@0 583 state = NS_HTML5META_SCANNER_DATA;
michael@0 584 NS_HTML5_CONTINUE(stateloop);
michael@0 585 }
michael@0 586 default: {
michael@0 587 state = NS_HTML5META_SCANNER_COMMENT;
michael@0 588 NS_HTML5_BREAK(commentstartloop);
michael@0 589 }
michael@0 590 }
michael@0 591 }
michael@0 592 commentstartloop_end: ;
michael@0 593 }
michael@0 594 case NS_HTML5META_SCANNER_COMMENT: {
michael@0 595 for (; ; ) {
michael@0 596 c = read();
michael@0 597 switch(c) {
michael@0 598 case -1: {
michael@0 599 NS_HTML5_BREAK(stateloop);
michael@0 600 }
michael@0 601 case '-': {
michael@0 602 state = NS_HTML5META_SCANNER_COMMENT_END_DASH;
michael@0 603 NS_HTML5_BREAK(commentloop);
michael@0 604 }
michael@0 605 default: {
michael@0 606 continue;
michael@0 607 }
michael@0 608 }
michael@0 609 }
michael@0 610 commentloop_end: ;
michael@0 611 }
michael@0 612 case NS_HTML5META_SCANNER_COMMENT_END_DASH: {
michael@0 613 for (; ; ) {
michael@0 614 c = read();
michael@0 615 switch(c) {
michael@0 616 case -1: {
michael@0 617 NS_HTML5_BREAK(stateloop);
michael@0 618 }
michael@0 619 case '-': {
michael@0 620 state = NS_HTML5META_SCANNER_COMMENT_END;
michael@0 621 NS_HTML5_BREAK(commentenddashloop);
michael@0 622 }
michael@0 623 default: {
michael@0 624 state = NS_HTML5META_SCANNER_COMMENT;
michael@0 625 NS_HTML5_CONTINUE(stateloop);
michael@0 626 }
michael@0 627 }
michael@0 628 }
michael@0 629 commentenddashloop_end: ;
michael@0 630 }
michael@0 631 case NS_HTML5META_SCANNER_COMMENT_END: {
michael@0 632 for (; ; ) {
michael@0 633 c = read();
michael@0 634 switch(c) {
michael@0 635 case -1: {
michael@0 636 NS_HTML5_BREAK(stateloop);
michael@0 637 }
michael@0 638 case '>': {
michael@0 639 state = NS_HTML5META_SCANNER_DATA;
michael@0 640 NS_HTML5_CONTINUE(stateloop);
michael@0 641 }
michael@0 642 case '-': {
michael@0 643 continue;
michael@0 644 }
michael@0 645 default: {
michael@0 646 state = NS_HTML5META_SCANNER_COMMENT;
michael@0 647 NS_HTML5_CONTINUE(stateloop);
michael@0 648 }
michael@0 649 }
michael@0 650 }
michael@0 651 }
michael@0 652 case NS_HTML5META_SCANNER_COMMENT_START_DASH: {
michael@0 653 c = read();
michael@0 654 switch(c) {
michael@0 655 case -1: {
michael@0 656 NS_HTML5_BREAK(stateloop);
michael@0 657 }
michael@0 658 case '-': {
michael@0 659 state = NS_HTML5META_SCANNER_COMMENT_END;
michael@0 660 NS_HTML5_CONTINUE(stateloop);
michael@0 661 }
michael@0 662 case '>': {
michael@0 663 state = NS_HTML5META_SCANNER_DATA;
michael@0 664 NS_HTML5_CONTINUE(stateloop);
michael@0 665 }
michael@0 666 default: {
michael@0 667 state = NS_HTML5META_SCANNER_COMMENT;
michael@0 668 NS_HTML5_CONTINUE(stateloop);
michael@0 669 }
michael@0 670 }
michael@0 671 }
michael@0 672 case NS_HTML5META_SCANNER_ATTRIBUTE_VALUE_SINGLE_QUOTED: {
michael@0 673 for (; ; ) {
michael@0 674 if (reconsume) {
michael@0 675 reconsume = false;
michael@0 676 } else {
michael@0 677 c = read();
michael@0 678 }
michael@0 679 switch(c) {
michael@0 680 case -1: {
michael@0 681 NS_HTML5_BREAK(stateloop);
michael@0 682 }
michael@0 683 case '\'': {
michael@0 684 handleAttributeValue();
michael@0 685 state = NS_HTML5META_SCANNER_AFTER_ATTRIBUTE_VALUE_QUOTED;
michael@0 686 NS_HTML5_CONTINUE(stateloop);
michael@0 687 }
michael@0 688 default: {
michael@0 689 handleCharInAttributeValue(c);
michael@0 690 continue;
michael@0 691 }
michael@0 692 }
michael@0 693 }
michael@0 694 }
michael@0 695 case NS_HTML5META_SCANNER_SCAN_UNTIL_GT: {
michael@0 696 for (; ; ) {
michael@0 697 if (reconsume) {
michael@0 698 reconsume = false;
michael@0 699 } else {
michael@0 700 c = read();
michael@0 701 }
michael@0 702 switch(c) {
michael@0 703 case -1: {
michael@0 704 NS_HTML5_BREAK(stateloop);
michael@0 705 }
michael@0 706 case '>': {
michael@0 707 state = NS_HTML5META_SCANNER_DATA;
michael@0 708 NS_HTML5_CONTINUE(stateloop);
michael@0 709 }
michael@0 710 default: {
michael@0 711 continue;
michael@0 712 }
michael@0 713 }
michael@0 714 }
michael@0 715 }
michael@0 716 }
michael@0 717 }
michael@0 718 stateloop_end: ;
michael@0 719 stateSave = state;
michael@0 720 }
michael@0 721
michael@0 722 void
michael@0 723 nsHtml5MetaScanner::handleCharInAttributeValue(int32_t c)
michael@0 724 {
michael@0 725 if (metaState == NS_HTML5META_SCANNER_A) {
michael@0 726 if (contentIndex == CONTENT.length || charsetIndex == CHARSET.length) {
michael@0 727 addToBuffer(c);
michael@0 728 } else if (httpEquivIndex == HTTP_EQUIV.length) {
michael@0 729 if (contentTypeIndex < CONTENT_TYPE.length && toAsciiLowerCase(c) == CONTENT_TYPE[contentTypeIndex]) {
michael@0 730 ++contentTypeIndex;
michael@0 731 } else {
michael@0 732 contentTypeIndex = INT32_MAX;
michael@0 733 }
michael@0 734 }
michael@0 735 }
michael@0 736 }
michael@0 737
michael@0 738 void
michael@0 739 nsHtml5MetaScanner::addToBuffer(int32_t c)
michael@0 740 {
michael@0 741 if (strBufLen == strBuf.length) {
michael@0 742 jArray<char16_t,int32_t> newBuf = jArray<char16_t,int32_t>::newJArray(strBuf.length + (strBuf.length << 1));
michael@0 743 nsHtml5ArrayCopy::arraycopy(strBuf, newBuf, strBuf.length);
michael@0 744 strBuf = newBuf;
michael@0 745 }
michael@0 746 strBuf[strBufLen++] = (char16_t) c;
michael@0 747 }
michael@0 748
michael@0 749 void
michael@0 750 nsHtml5MetaScanner::handleAttributeValue()
michael@0 751 {
michael@0 752 if (metaState != NS_HTML5META_SCANNER_A) {
michael@0 753 return;
michael@0 754 }
michael@0 755 if (contentIndex == CONTENT.length && !content) {
michael@0 756 content = nsHtml5Portability::newStringFromBuffer(strBuf, 0, strBufLen);
michael@0 757 return;
michael@0 758 }
michael@0 759 if (charsetIndex == CHARSET.length && !charset) {
michael@0 760 charset = nsHtml5Portability::newStringFromBuffer(strBuf, 0, strBufLen);
michael@0 761 return;
michael@0 762 }
michael@0 763 if (httpEquivIndex == HTTP_EQUIV.length && httpEquivState == NS_HTML5META_SCANNER_HTTP_EQUIV_NOT_SEEN) {
michael@0 764 httpEquivState = (contentTypeIndex == CONTENT_TYPE.length) ? NS_HTML5META_SCANNER_HTTP_EQUIV_CONTENT_TYPE : NS_HTML5META_SCANNER_HTTP_EQUIV_OTHER;
michael@0 765 return;
michael@0 766 }
michael@0 767 }
michael@0 768
michael@0 769 bool
michael@0 770 nsHtml5MetaScanner::handleTag()
michael@0 771 {
michael@0 772 bool stop = handleTagInner();
michael@0 773 nsHtml5Portability::releaseString(content);
michael@0 774 content = nullptr;
michael@0 775 nsHtml5Portability::releaseString(charset);
michael@0 776 charset = nullptr;
michael@0 777 httpEquivState = NS_HTML5META_SCANNER_HTTP_EQUIV_NOT_SEEN;
michael@0 778 return stop;
michael@0 779 }
michael@0 780
michael@0 781 bool
michael@0 782 nsHtml5MetaScanner::handleTagInner()
michael@0 783 {
michael@0 784 if (!!charset && tryCharset(charset)) {
michael@0 785 return true;
michael@0 786 }
michael@0 787 if (!!content && httpEquivState == NS_HTML5META_SCANNER_HTTP_EQUIV_CONTENT_TYPE) {
michael@0 788 nsString* extract = nsHtml5TreeBuilder::extractCharsetFromContent(content);
michael@0 789 if (!extract) {
michael@0 790 return false;
michael@0 791 }
michael@0 792 bool success = tryCharset(extract);
michael@0 793 nsHtml5Portability::releaseString(extract);
michael@0 794 return success;
michael@0 795 }
michael@0 796 return false;
michael@0 797 }
michael@0 798
michael@0 799 void
michael@0 800 nsHtml5MetaScanner::initializeStatics()
michael@0 801 {
michael@0 802 }
michael@0 803
michael@0 804 void
michael@0 805 nsHtml5MetaScanner::releaseStatics()
michael@0 806 {
michael@0 807 }
michael@0 808
michael@0 809
michael@0 810 #include "nsHtml5MetaScannerCppSupplement.h"
michael@0 811

mercurial