Son CV dans un terminal web en Javascript! https://terminal-cv.gregandev.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

900 lines
36 KiB

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var decode_codepoint_1 = __importDefault(require("entities/lib/decode_codepoint"));
var decode_1 = require("entities/lib/decode");
function whitespace(c) {
return (c === 32 /* Space */ ||
c === 10 /* NewLine */ ||
c === 9 /* Tab */ ||
c === 12 /* FormFeed */ ||
c === 13 /* CarriageReturn */);
}
function isASCIIAlpha(c) {
return ((c >= 97 /* LowerA */ && c <= 122 /* LowerZ */) ||
(c >= 65 /* UpperA */ && c <= 90 /* UpperZ */));
}
function ifElseState(upper, SUCCESS, FAILURE) {
var upperCode = upper.charCodeAt(0);
var lowerCode = upper.toLowerCase().charCodeAt(0);
return function (t, c) {
if (c === lowerCode || c === upperCode) {
t._state = SUCCESS;
}
else {
t._state = FAILURE;
t._index--;
}
};
}
var stateBeforeCdata1 = ifElseState("C", 24 /* BeforeCdata2 */, 16 /* InDeclaration */);
var stateBeforeCdata2 = ifElseState("D", 25 /* BeforeCdata3 */, 16 /* InDeclaration */);
var stateBeforeCdata3 = ifElseState("A", 26 /* BeforeCdata4 */, 16 /* InDeclaration */);
var stateBeforeCdata4 = ifElseState("T", 27 /* BeforeCdata5 */, 16 /* InDeclaration */);
var stateBeforeCdata5 = ifElseState("A", 28 /* BeforeCdata6 */, 16 /* InDeclaration */);
var stateBeforeScript1 = ifElseState("R", 35 /* BeforeScript2 */, 3 /* InTagName */);
var stateBeforeScript2 = ifElseState("I", 36 /* BeforeScript3 */, 3 /* InTagName */);
var stateBeforeScript3 = ifElseState("P", 37 /* BeforeScript4 */, 3 /* InTagName */);
var stateBeforeScript4 = ifElseState("T", 38 /* BeforeScript5 */, 3 /* InTagName */);
var stateAfterScript1 = ifElseState("R", 40 /* AfterScript2 */, 1 /* Text */);
var stateAfterScript2 = ifElseState("I", 41 /* AfterScript3 */, 1 /* Text */);
var stateAfterScript3 = ifElseState("P", 42 /* AfterScript4 */, 1 /* Text */);
var stateAfterScript4 = ifElseState("T", 43 /* AfterScript5 */, 1 /* Text */);
var stateBeforeStyle1 = ifElseState("Y", 45 /* BeforeStyle2 */, 3 /* InTagName */);
var stateBeforeStyle2 = ifElseState("L", 46 /* BeforeStyle3 */, 3 /* InTagName */);
var stateBeforeStyle3 = ifElseState("E", 47 /* BeforeStyle4 */, 3 /* InTagName */);
var stateAfterStyle1 = ifElseState("Y", 49 /* AfterStyle2 */, 1 /* Text */);
var stateAfterStyle2 = ifElseState("L", 50 /* AfterStyle3 */, 1 /* Text */);
var stateAfterStyle3 = ifElseState("E", 51 /* AfterStyle4 */, 1 /* Text */);
var stateBeforeSpecialT = ifElseState("I", 54 /* BeforeTitle1 */, 3 /* InTagName */);
var stateBeforeTitle1 = ifElseState("T", 55 /* BeforeTitle2 */, 3 /* InTagName */);
var stateBeforeTitle2 = ifElseState("L", 56 /* BeforeTitle3 */, 3 /* InTagName */);
var stateBeforeTitle3 = ifElseState("E", 57 /* BeforeTitle4 */, 3 /* InTagName */);
var stateBeforeSpecialTEnd = ifElseState("I", 58 /* AfterTitle1 */, 1 /* Text */);
var stateAfterTitle1 = ifElseState("T", 59 /* AfterTitle2 */, 1 /* Text */);
var stateAfterTitle2 = ifElseState("L", 60 /* AfterTitle3 */, 1 /* Text */);
var stateAfterTitle3 = ifElseState("E", 61 /* AfterTitle4 */, 1 /* Text */);
var stateBeforeNumericEntity = ifElseState("X", 66 /* InHexEntity */, 65 /* InNumericEntity */);
var Tokenizer = /** @class */ (function () {
function Tokenizer(_a, cbs) {
var _b = _a.xmlMode, xmlMode = _b === void 0 ? false : _b, _c = _a.decodeEntities, decodeEntities = _c === void 0 ? true : _c;
this.cbs = cbs;
/** The current state the tokenizer is in. */
this._state = 1 /* Text */;
/** The read buffer. */
this.buffer = "";
/** The beginning of the section that is currently being read. */
this.sectionStart = 0;
/** The index within the buffer that we are currently looking at. */
this._index = 0;
/**
* Data that has already been processed will be removed from the buffer occasionally.
* `_bufferOffset` keeps track of how many characters have been removed, to make sure position information is accurate.
*/
this.bufferOffset = 0;
/** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
this.baseState = 1 /* Text */;
/** For special parsing behavior inside of script and style tags. */
this.special = 1 /* None */;
/** Indicates whether the tokenizer has been paused. */
this.running = true;
/** Indicates whether the tokenizer has finished running / `.end` has been called. */
this.ended = false;
this.trieIndex = 0;
this.trieCurrent = 0;
this.trieResult = null;
this.trieExcess = 0;
this.xmlMode = xmlMode;
this.decodeEntities = decodeEntities;
this.entityTrie = xmlMode ? decode_1.xmlDecodeTree : decode_1.htmlDecodeTree;
}
Tokenizer.prototype.reset = function () {
this._state = 1 /* Text */;
this.buffer = "";
this.sectionStart = 0;
this._index = 0;
this.bufferOffset = 0;
this.baseState = 1 /* Text */;
this.special = 1 /* None */;
this.running = true;
this.ended = false;
};
Tokenizer.prototype.write = function (chunk) {
if (this.ended)
return this.cbs.onerror(Error(".write() after done!"));
if (this.buffer.length)
this.buffer += chunk;
else
this.buffer = chunk;
this.parse();
};
Tokenizer.prototype.end = function (chunk) {
if (this.ended)
return this.cbs.onerror(Error(".end() after done!"));
if (chunk)
this.write(chunk);
this.ended = true;
if (this.running)
this.finish();
};
Tokenizer.prototype.pause = function () {
this.running = false;
};
Tokenizer.prototype.resume = function () {
this.running = true;
if (this._index < this.buffer.length) {
this.parse();
}
if (this.ended) {
this.finish();
}
};
/**
* The start of the current section.
*/
Tokenizer.prototype.getAbsoluteSectionStart = function () {
return this.sectionStart + this.bufferOffset;
};
/**
* The current index within all of the written data.
*/
Tokenizer.prototype.getAbsoluteIndex = function () {
return this.bufferOffset + this._index;
};
Tokenizer.prototype.stateText = function (c) {
if (c === 60 /* Lt */) {
if (this._index > this.sectionStart) {
this.cbs.ontext(this.getSection());
}
this._state = 2 /* BeforeTagName */;
this.sectionStart = this._index;
}
else if (this.decodeEntities &&
c === 38 /* Amp */ &&
(this.special === 1 /* None */ || this.special === 4 /* Title */)) {
if (this._index > this.sectionStart) {
this.cbs.ontext(this.getSection());
}
this.baseState = 1 /* Text */;
this._state = 62 /* BeforeEntity */;
this.sectionStart = this._index;
}
};
/**
* HTML only allows ASCII alpha characters (a-z and A-Z) at the beginning of a tag name.
*
* XML allows a lot more characters here (@see https://www.w3.org/TR/REC-xml/#NT-NameStartChar).
* We allow anything that wouldn't end the tag.
*/
Tokenizer.prototype.isTagStartChar = function (c) {
return (isASCIIAlpha(c) ||
(this.xmlMode &&
!whitespace(c) &&
c !== 47 /* Slash */ &&
c !== 62 /* Gt */));
};
Tokenizer.prototype.stateBeforeTagName = function (c) {
if (c === 47 /* Slash */) {
this._state = 5 /* BeforeClosingTagName */;
}
else if (c === 60 /* Lt */) {
this.cbs.ontext(this.getSection());
this.sectionStart = this._index;
}
else if (c === 62 /* Gt */ ||
this.special !== 1 /* None */ ||
whitespace(c)) {
this._state = 1 /* Text */;
}
else if (c === 33 /* ExclamationMark */) {
this._state = 15 /* BeforeDeclaration */;
this.sectionStart = this._index + 1;
}
else if (c === 63 /* Questionmark */) {
this._state = 17 /* InProcessingInstruction */;
this.sectionStart = this._index + 1;
}
else if (!this.isTagStartChar(c)) {
this._state = 1 /* Text */;
}
else {
this._state =
!this.xmlMode &&
(c === 115 /* LowerS */ || c === 83 /* UpperS */)
? 32 /* BeforeSpecialS */
: !this.xmlMode &&
(c === 116 /* LowerT */ || c === 84 /* UpperT */)
? 52 /* BeforeSpecialT */
: 3 /* InTagName */;
this.sectionStart = this._index;
}
};
Tokenizer.prototype.stateInTagName = function (c) {
if (c === 47 /* Slash */ || c === 62 /* Gt */ || whitespace(c)) {
this.cbs.onopentagname(this.getSection());
this.sectionStart = -1;
this._state = 8 /* BeforeAttributeName */;
this.stateBeforeAttributeName(c);
}
};
Tokenizer.prototype.stateBeforeClosingTagName = function (c) {
if (whitespace(c)) {
// Ignore
}
else if (c === 62 /* Gt */) {
this._state = 1 /* Text */;
}
else if (this.special !== 1 /* None */) {
if (this.special !== 4 /* Title */ &&
(c === 115 /* LowerS */ || c === 83 /* UpperS */)) {
this._state = 33 /* BeforeSpecialSEnd */;
}
else if (this.special === 4 /* Title */ &&
(c === 116 /* LowerT */ || c === 84 /* UpperT */)) {
this._state = 53 /* BeforeSpecialTEnd */;
}
else {
this._state = 1 /* Text */;
this.stateText(c);
}
}
else if (!this.isTagStartChar(c)) {
this._state = 20 /* InSpecialComment */;
this.sectionStart = this._index;
}
else {
this._state = 6 /* InClosingTagName */;
this.sectionStart = this._index;
}
};
Tokenizer.prototype.stateInClosingTagName = function (c) {
if (c === 62 /* Gt */ || whitespace(c)) {
this.cbs.onclosetag(this.getSection());
this.sectionStart = -1;
this._state = 7 /* AfterClosingTagName */;
this.stateAfterClosingTagName(c);
}
};
Tokenizer.prototype.stateAfterClosingTagName = function (c) {
// Skip everything until ">"
if (c === 62 /* Gt */) {
this._state = 1 /* Text */;
this.sectionStart = this._index + 1;
}
};
Tokenizer.prototype.stateBeforeAttributeName = function (c) {
if (c === 62 /* Gt */) {
this.cbs.onopentagend();
this._state = 1 /* Text */;
this.sectionStart = this._index + 1;
}
else if (c === 47 /* Slash */) {
this._state = 4 /* InSelfClosingTag */;
}
else if (!whitespace(c)) {
this._state = 9 /* InAttributeName */;
this.sectionStart = this._index;
}
};
Tokenizer.prototype.stateInSelfClosingTag = function (c) {
if (c === 62 /* Gt */) {
this.cbs.onselfclosingtag();
this._state = 1 /* Text */;
this.sectionStart = this._index + 1;
this.special = 1 /* None */; // Reset special state, in case of self-closing special tags
}
else if (!whitespace(c)) {
this._state = 8 /* BeforeAttributeName */;
this.stateBeforeAttributeName(c);
}
};
Tokenizer.prototype.stateInAttributeName = function (c) {
if (c === 61 /* Eq */ ||
c === 47 /* Slash */ ||
c === 62 /* Gt */ ||
whitespace(c)) {
this.cbs.onattribname(this.getSection());
this.sectionStart = -1;
this._state = 10 /* AfterAttributeName */;
this.stateAfterAttributeName(c);
}
};
Tokenizer.prototype.stateAfterAttributeName = function (c) {
if (c === 61 /* Eq */) {
this._state = 11 /* BeforeAttributeValue */;
}
else if (c === 47 /* Slash */ || c === 62 /* Gt */) {
this.cbs.onattribend(undefined);
this._state = 8 /* BeforeAttributeName */;
this.stateBeforeAttributeName(c);
}
else if (!whitespace(c)) {
this.cbs.onattribend(undefined);
this._state = 9 /* InAttributeName */;
this.sectionStart = this._index;
}
};
Tokenizer.prototype.stateBeforeAttributeValue = function (c) {
if (c === 34 /* DoubleQuote */) {
this._state = 12 /* InAttributeValueDq */;
this.sectionStart = this._index + 1;
}
else if (c === 39 /* SingleQuote */) {
this._state = 13 /* InAttributeValueSq */;
this.sectionStart = this._index + 1;
}
else if (!whitespace(c)) {
this.sectionStart = this._index;
this._state = 14 /* InAttributeValueNq */;
this.stateInAttributeValueNoQuotes(c); // Reconsume token
}
};
Tokenizer.prototype.handleInAttributeValue = function (c, quote) {
if (c === quote) {
this.cbs.onattribdata(this.getSection());
this.sectionStart = -1;
this.cbs.onattribend(String.fromCharCode(quote));
this._state = 8 /* BeforeAttributeName */;
}
else if (this.decodeEntities && c === 38 /* Amp */) {
this.cbs.onattribdata(this.getSection());
this.baseState = this._state;
this._state = 62 /* BeforeEntity */;
this.sectionStart = this._index;
}
};
Tokenizer.prototype.stateInAttributeValueDoubleQuotes = function (c) {
this.handleInAttributeValue(c, 34 /* DoubleQuote */);
};
Tokenizer.prototype.stateInAttributeValueSingleQuotes = function (c) {
this.handleInAttributeValue(c, 39 /* SingleQuote */);
};
Tokenizer.prototype.stateInAttributeValueNoQuotes = function (c) {
if (whitespace(c) || c === 62 /* Gt */) {
this.cbs.onattribdata(this.getSection());
this.sectionStart = -1;
this.cbs.onattribend(null);
this._state = 8 /* BeforeAttributeName */;
this.stateBeforeAttributeName(c);
}
else if (this.decodeEntities && c === 38 /* Amp */) {
this.cbs.onattribdata(this.getSection());
this.baseState = this._state;
this._state = 62 /* BeforeEntity */;
this.sectionStart = this._index;
}
};
Tokenizer.prototype.stateBeforeDeclaration = function (c) {
this._state =
c === 91 /* OpeningSquareBracket */
? 23 /* BeforeCdata1 */
: c === 45 /* Dash */
? 18 /* BeforeComment */
: 16 /* InDeclaration */;
};
Tokenizer.prototype.stateInDeclaration = function (c) {
if (c === 62 /* Gt */) {
this.cbs.ondeclaration(this.getSection());
this._state = 1 /* Text */;
this.sectionStart = this._index + 1;
}
};
Tokenizer.prototype.stateInProcessingInstruction = function (c) {
if (c === 62 /* Gt */) {
this.cbs.onprocessinginstruction(this.getSection());
this._state = 1 /* Text */;
this.sectionStart = this._index + 1;
}
};
Tokenizer.prototype.stateBeforeComment = function (c) {
if (c === 45 /* Dash */) {
this._state = 19 /* InComment */;
this.sectionStart = this._index + 1;
}
else {
this._state = 16 /* InDeclaration */;
}
};
Tokenizer.prototype.stateInComment = function (c) {
if (c === 45 /* Dash */)
this._state = 21 /* AfterComment1 */;
};
Tokenizer.prototype.stateInSpecialComment = function (c) {
if (c === 62 /* Gt */) {
this.cbs.oncomment(this.buffer.substring(this.sectionStart, this._index));
this._state = 1 /* Text */;
this.sectionStart = this._index + 1;
}
};
Tokenizer.prototype.stateAfterComment1 = function (c) {
if (c === 45 /* Dash */) {
this._state = 22 /* AfterComment2 */;
}
else {
this._state = 19 /* InComment */;
}
};
Tokenizer.prototype.stateAfterComment2 = function (c) {
if (c === 62 /* Gt */) {
// Remove 2 trailing chars
this.cbs.oncomment(this.buffer.substring(this.sectionStart, this._index - 2));
this._state = 1 /* Text */;
this.sectionStart = this._index + 1;
}
else if (c !== 45 /* Dash */) {
this._state = 19 /* InComment */;
}
// Else: stay in AFTER_COMMENT_2 (`--->`)
};
Tokenizer.prototype.stateBeforeCdata6 = function (c) {
if (c === 91 /* OpeningSquareBracket */) {
this._state = 29 /* InCdata */;
this.sectionStart = this._index + 1;
}
else {
this._state = 16 /* InDeclaration */;
this.stateInDeclaration(c);
}
};
Tokenizer.prototype.stateInCdata = function (c) {
if (c === 93 /* ClosingSquareBracket */)
this._state = 30 /* AfterCdata1 */;
};
Tokenizer.prototype.stateAfterCdata1 = function (c) {
if (c === 93 /* ClosingSquareBracket */)
this._state = 31 /* AfterCdata2 */;
else
this._state = 29 /* InCdata */;
};
Tokenizer.prototype.stateAfterCdata2 = function (c) {
if (c === 62 /* Gt */) {
// Remove 2 trailing chars
this.cbs.oncdata(this.buffer.substring(this.sectionStart, this._index - 2));
this._state = 1 /* Text */;
this.sectionStart = this._index + 1;
}
else if (c !== 93 /* ClosingSquareBracket */) {
this._state = 29 /* InCdata */;
}
// Else: stay in AFTER_CDATA_2 (`]]]>`)
};
Tokenizer.prototype.stateBeforeSpecialS = function (c) {
if (c === 99 /* LowerC */ || c === 67 /* UpperC */) {
this._state = 34 /* BeforeScript1 */;
}
else if (c === 116 /* LowerT */ || c === 84 /* UpperT */) {
this._state = 44 /* BeforeStyle1 */;
}
else {
this._state = 3 /* InTagName */;
this.stateInTagName(c); // Consume the token again
}
};
Tokenizer.prototype.stateBeforeSpecialSEnd = function (c) {
if (this.special === 2 /* Script */ &&
(c === 99 /* LowerC */ || c === 67 /* UpperC */)) {
this._state = 39 /* AfterScript1 */;
}
else if (this.special === 3 /* Style */ &&
(c === 116 /* LowerT */ || c === 84 /* UpperT */)) {
this._state = 48 /* AfterStyle1 */;
}
else
this._state = 1 /* Text */;
};
Tokenizer.prototype.stateBeforeSpecialLast = function (c, special) {
if (c === 47 /* Slash */ || c === 62 /* Gt */ || whitespace(c)) {
this.special = special;
}
this._state = 3 /* InTagName */;
this.stateInTagName(c); // Consume the token again
};
Tokenizer.prototype.stateAfterSpecialLast = function (c, sectionStartOffset) {
if (c === 62 /* Gt */ || whitespace(c)) {
this.sectionStart = this._index - sectionStartOffset;
this.special = 1 /* None */;
this._state = 6 /* InClosingTagName */;
this.stateInClosingTagName(c); // Reconsume the token
}
else
this._state = 1 /* Text */;
};
Tokenizer.prototype.stateBeforeEntity = function (c) {
if (c === 35 /* Num */) {
this._state = 63 /* BeforeNumericEntity */;
}
else if (c === 38 /* Amp */) {
// We have two `&` characters in a row. Emit the first one.
this.emitPartial(this.getSection());
this.sectionStart = this._index;
}
else {
this._state = 64 /* InNamedEntity */;
this.trieIndex = 0;
this.trieCurrent = this.entityTrie[0];
this.trieResult = null;
// Start excess with 1 to include the '&'
this.trieExcess = 1;
this._index--;
}
};
Tokenizer.prototype.stateInNamedEntity = function (c) {
this.trieExcess += 1;
this.trieIndex = (0, decode_1.determineBranch)(this.entityTrie, this.trieCurrent, this.trieIndex + 1, c);
if (this.trieIndex < 0) {
this.emitNamedEntity();
this._index--;
return;
}
this.trieCurrent = this.entityTrie[this.trieIndex];
// If the branch is a value, store it and continue
if (this.trieCurrent & decode_1.BinTrieFlags.HAS_VALUE) {
// If we have a legacy entity while parsing strictly, just skip the number of bytes
if (!this.allowLegacyEntity() && c !== 59 /* Semi */) {
// No need to consider multi-byte values, as the legacy entity is always a single byte
this.trieIndex += 1;
}
else {
// If this is a surrogate pair, combine the higher bits from the node with the next byte
this.trieResult =
this.trieCurrent & decode_1.BinTrieFlags.MULTI_BYTE
? String.fromCharCode(this.entityTrie[++this.trieIndex], this.entityTrie[++this.trieIndex])
: String.fromCharCode(this.entityTrie[++this.trieIndex]);
this.trieExcess = 0;
}
}
};
Tokenizer.prototype.emitNamedEntity = function () {
if (this.trieResult) {
this.emitPartial(this.trieResult);
}
this.sectionStart = this._index - this.trieExcess + 1;
this._state = this.baseState;
};
Tokenizer.prototype.decodeNumericEntity = function (base, strict) {
var sectionStart = this.sectionStart + 2 + (base >> 4);
if (sectionStart !== this._index) {
// Parse entity
var entity = this.buffer.substring(sectionStart, this._index);
var parsed = parseInt(entity, base);
this.emitPartial((0, decode_codepoint_1.default)(parsed));
this.sectionStart = this._index + Number(strict);
}
this._state = this.baseState;
};
Tokenizer.prototype.stateInNumericEntity = function (c) {
if (c === 59 /* Semi */) {
this.decodeNumericEntity(10, true);
}
else if (c < 48 /* Zero */ || c > 57 /* Nine */) {
if (this.allowLegacyEntity()) {
this.decodeNumericEntity(10, false);
}
else {
this._state = this.baseState;
}
this._index--;
}
};
Tokenizer.prototype.stateInHexEntity = function (c) {
if (c === 59 /* Semi */) {
this.decodeNumericEntity(16, true);
}
else if ((c < 97 /* LowerA */ || c > 102 /* LowerF */) &&
(c < 65 /* UpperA */ || c > 70 /* UpperF */) &&
(c < 48 /* Zero */ || c > 57 /* Nine */)) {
if (this.allowLegacyEntity()) {
this.decodeNumericEntity(16, false);
}
else {
this._state = this.baseState;
}
this._index--;
}
};
Tokenizer.prototype.allowLegacyEntity = function () {
return !this.xmlMode && this.baseState === 1 /* Text */;
};
/**
* Remove data that has already been consumed from the buffer.
*/
Tokenizer.prototype.cleanup = function () {
// If we are inside of text, emit what we already have.
if (this.running &&
this._state === 1 /* Text */ &&
this.sectionStart !== this._index) {
// TODO: We could emit attribute data here as well.
this.cbs.ontext(this.buffer.substr(this.sectionStart));
this.sectionStart = this._index;
}
var start = this.sectionStart < 0 ? this._index : this.sectionStart;
this.buffer =
start === this.buffer.length ? "" : this.buffer.substr(start);
this._index -= start;
this.bufferOffset += start;
if (this.sectionStart > 0) {
this.sectionStart = 0;
}
};
/**
* Iterates through the buffer, calling the function corresponding to the current state.
*
* States that are more likely to be hit are higher up, as a performance improvement.
*/
Tokenizer.prototype.parse = function () {
while (this._index < this.buffer.length && this.running) {
var c = this.buffer.charCodeAt(this._index);
if (this._state === 1 /* Text */) {
this.stateText(c);
}
else if (this._state === 12 /* InAttributeValueDq */) {
this.stateInAttributeValueDoubleQuotes(c);
}
else if (this._state === 9 /* InAttributeName */) {
this.stateInAttributeName(c);
}
else if (this._state === 19 /* InComment */) {
this.stateInComment(c);
}
else if (this._state === 20 /* InSpecialComment */) {
this.stateInSpecialComment(c);
}
else if (this._state === 8 /* BeforeAttributeName */) {
this.stateBeforeAttributeName(c);
}
else if (this._state === 3 /* InTagName */) {
this.stateInTagName(c);
}
else if (this._state === 6 /* InClosingTagName */) {
this.stateInClosingTagName(c);
}
else if (this._state === 2 /* BeforeTagName */) {
this.stateBeforeTagName(c);
}
else if (this._state === 10 /* AfterAttributeName */) {
this.stateAfterAttributeName(c);
}
else if (this._state === 13 /* InAttributeValueSq */) {
this.stateInAttributeValueSingleQuotes(c);
}
else if (this._state === 11 /* BeforeAttributeValue */) {
this.stateBeforeAttributeValue(c);
}
else if (this._state === 5 /* BeforeClosingTagName */) {
this.stateBeforeClosingTagName(c);
}
else if (this._state === 7 /* AfterClosingTagName */) {
this.stateAfterClosingTagName(c);
}
else if (this._state === 32 /* BeforeSpecialS */) {
this.stateBeforeSpecialS(c);
}
else if (this._state === 21 /* AfterComment1 */) {
this.stateAfterComment1(c);
}
else if (this._state === 14 /* InAttributeValueNq */) {
this.stateInAttributeValueNoQuotes(c);
}
else if (this._state === 4 /* InSelfClosingTag */) {
this.stateInSelfClosingTag(c);
}
else if (this._state === 16 /* InDeclaration */) {
this.stateInDeclaration(c);
}
else if (this._state === 15 /* BeforeDeclaration */) {
this.stateBeforeDeclaration(c);
}
else if (this._state === 22 /* AfterComment2 */) {
this.stateAfterComment2(c);
}
else if (this._state === 18 /* BeforeComment */) {
this.stateBeforeComment(c);
}
else if (this._state === 33 /* BeforeSpecialSEnd */) {
this.stateBeforeSpecialSEnd(c);
}
else if (this._state === 53 /* BeforeSpecialTEnd */) {
stateBeforeSpecialTEnd(this, c);
}
else if (this._state === 39 /* AfterScript1 */) {
stateAfterScript1(this, c);
}
else if (this._state === 40 /* AfterScript2 */) {
stateAfterScript2(this, c);
}
else if (this._state === 41 /* AfterScript3 */) {
stateAfterScript3(this, c);
}
else if (this._state === 34 /* BeforeScript1 */) {
stateBeforeScript1(this, c);
}
else if (this._state === 35 /* BeforeScript2 */) {
stateBeforeScript2(this, c);
}
else if (this._state === 36 /* BeforeScript3 */) {
stateBeforeScript3(this, c);
}
else if (this._state === 37 /* BeforeScript4 */) {
stateBeforeScript4(this, c);
}
else if (this._state === 38 /* BeforeScript5 */) {
this.stateBeforeSpecialLast(c, 2 /* Script */);
}
else if (this._state === 42 /* AfterScript4 */) {
stateAfterScript4(this, c);
}
else if (this._state === 43 /* AfterScript5 */) {
this.stateAfterSpecialLast(c, 6);
}
else if (this._state === 44 /* BeforeStyle1 */) {
stateBeforeStyle1(this, c);
}
else if (this._state === 29 /* InCdata */) {
this.stateInCdata(c);
}
else if (this._state === 45 /* BeforeStyle2 */) {
stateBeforeStyle2(this, c);
}
else if (this._state === 46 /* BeforeStyle3 */) {
stateBeforeStyle3(this, c);
}
else if (this._state === 47 /* BeforeStyle4 */) {
this.stateBeforeSpecialLast(c, 3 /* Style */);
}
else if (this._state === 48 /* AfterStyle1 */) {
stateAfterStyle1(this, c);
}
else if (this._state === 49 /* AfterStyle2 */) {
stateAfterStyle2(this, c);
}
else if (this._state === 50 /* AfterStyle3 */) {
stateAfterStyle3(this, c);
}
else if (this._state === 51 /* AfterStyle4 */) {
this.stateAfterSpecialLast(c, 5);
}
else if (this._state === 52 /* BeforeSpecialT */) {
stateBeforeSpecialT(this, c);
}
else if (this._state === 54 /* BeforeTitle1 */) {
stateBeforeTitle1(this, c);
}
else if (this._state === 55 /* BeforeTitle2 */) {
stateBeforeTitle2(this, c);
}
else if (this._state === 56 /* BeforeTitle3 */) {
stateBeforeTitle3(this, c);
}
else if (this._state === 57 /* BeforeTitle4 */) {
this.stateBeforeSpecialLast(c, 4 /* Title */);
}
else if (this._state === 58 /* AfterTitle1 */) {
stateAfterTitle1(this, c);
}
else if (this._state === 59 /* AfterTitle2 */) {
stateAfterTitle2(this, c);
}
else if (this._state === 60 /* AfterTitle3 */) {
stateAfterTitle3(this, c);
}
else if (this._state === 61 /* AfterTitle4 */) {
this.stateAfterSpecialLast(c, 5);
}
else if (this._state === 17 /* InProcessingInstruction */) {
this.stateInProcessingInstruction(c);
}
else if (this._state === 64 /* InNamedEntity */) {
this.stateInNamedEntity(c);
}
else if (this._state === 23 /* BeforeCdata1 */) {
stateBeforeCdata1(this, c);
}
else if (this._state === 62 /* BeforeEntity */) {
this.stateBeforeEntity(c);
}
else if (this._state === 24 /* BeforeCdata2 */) {
stateBeforeCdata2(this, c);
}
else if (this._state === 25 /* BeforeCdata3 */) {
stateBeforeCdata3(this, c);
}
else if (this._state === 30 /* AfterCdata1 */) {
this.stateAfterCdata1(c);
}
else if (this._state === 31 /* AfterCdata2 */) {
this.stateAfterCdata2(c);
}
else if (this._state === 26 /* BeforeCdata4 */) {
stateBeforeCdata4(this, c);
}
else if (this._state === 27 /* BeforeCdata5 */) {
stateBeforeCdata5(this, c);
}
else if (this._state === 28 /* BeforeCdata6 */) {
this.stateBeforeCdata6(c);
}
else if (this._state === 66 /* InHexEntity */) {
this.stateInHexEntity(c);
}
else if (this._state === 65 /* InNumericEntity */) {
this.stateInNumericEntity(c);
}
else {
// `this._state === State.BeforeNumericEntity`
stateBeforeNumericEntity(this, c);
}
this._index++;
}
this.cleanup();
};
Tokenizer.prototype.finish = function () {
// If there is remaining data, emit it in a reasonable way
if (this.sectionStart < this._index) {
this.handleTrailingData();
}
this.cbs.onend();
};
/** Handle any trailing data. */
Tokenizer.prototype.handleTrailingData = function () {
var data = this.buffer.substr(this.sectionStart);
if (this._state === 29 /* InCdata */ ||
this._state === 30 /* AfterCdata1 */ ||
this._state === 31 /* AfterCdata2 */) {
this.cbs.oncdata(data);
}
else if (this._state === 19 /* InComment */ ||
this._state === 21 /* AfterComment1 */ ||
this._state === 22 /* AfterComment2 */) {
this.cbs.oncomment(data);
}
else if (this._state === 64 /* InNamedEntity */ && !this.xmlMode) {
// Increase excess for EOF
this.trieExcess++;
this.emitNamedEntity();
if (this.sectionStart < this._index) {
this._state = this.baseState;
this.handleTrailingData();
}
}
else if (this._state === 65 /* InNumericEntity */ && !this.xmlMode) {
this.decodeNumericEntity(10, false);
// All trailing data will have been consumed
}
else if (this._state === 66 /* InHexEntity */ && !this.xmlMode) {
this.decodeNumericEntity(16, false);
// All trailing data will have been consumed
}
else if (this._state === 3 /* InTagName */ ||
this._state === 8 /* BeforeAttributeName */ ||
this._state === 11 /* BeforeAttributeValue */ ||
this._state === 10 /* AfterAttributeName */ ||
this._state === 9 /* InAttributeName */ ||
this._state === 13 /* InAttributeValueSq */ ||
this._state === 12 /* InAttributeValueDq */ ||
this._state === 14 /* InAttributeValueNq */ ||
this._state === 6 /* InClosingTagName */) {
/*
* If we are currently in an opening or closing tag, us not calling the
* respective callback signals that the tag should be ignored.
*/
}
else {
this.cbs.ontext(data);
}
};
Tokenizer.prototype.getSection = function () {
return this.buffer.substring(this.sectionStart, this._index);
};
Tokenizer.prototype.emitPartial = function (value) {
if (this.baseState !== 1 /* Text */) {
this.cbs.onattribdata(value);
}
else {
this.cbs.ontext(value);
}
};
return Tokenizer;
}());
exports.default = Tokenizer;