(final: boolean)
| 1548 | } |
| 1549 | |
| 1550 | private parse(final: boolean): void { |
| 1551 | const s = this.buf |
| 1552 | const n = s.length |
| 1553 | // Positions of the next "&", CR and "]]>", so that text runs are checked |
| 1554 | // without searching past them repeatedly |
| 1555 | let nextAmp = -1 |
| 1556 | let nextCR = -1 |
| 1557 | let nextCdataEnd = -1 |
| 1558 | let i = 0 |
| 1559 | while (i < n) { |
| 1560 | if (s.charCodeAt(i) !== LT) { |
| 1561 | let j = s.indexOf("<", i) |
| 1562 | if (j === -1) { |
| 1563 | if (!final) break |
| 1564 | j = n |
| 1565 | } |
| 1566 | if (this.state !== CONTENT) { |
| 1567 | this.checkSize(i, j) |
| 1568 | this.whitespace(s, i, j) |
| 1569 | } else { |
| 1570 | this.addText(i, j - i) |
| 1571 | if (nextCdataEnd < i) nextCdataEnd = indexOrEnd(s, "]]>", i) |
| 1572 | if (nextCdataEnd < j) throw this.syntax("\"]]>\" is not allowed in text", nextCdataEnd) |
| 1573 | if (nextAmp < i) nextAmp = indexOrEnd(s, "&", i) |
| 1574 | if (nextCR < i) nextCR = indexOrEnd(s, "\r", i) |
| 1575 | const raw = s.slice(i, j) |
| 1576 | this.text += nextAmp >= j |
| 1577 | ? (nextCR >= j ? raw : normalizeLines(raw)) |
| 1578 | : this.decodeText(raw, i, false, nextCR < j) |
| 1579 | } |
| 1580 | i = j |
| 1581 | continue |
| 1582 | } |
| 1583 | // Markup is parsed from at most maxTokenSize + 1 characters, so that its |
| 1584 | // errors do not depend on how the input is chunked |
| 1585 | const long = n - i > this.maxTokenSize |
| 1586 | const end = this.markup(long ? s.slice(0, i + this.maxTokenSize + 1) : s, i) |
| 1587 | if (end === -1) { |
| 1588 | if (long) throw this.tokenLimit(this.base + i) |
| 1589 | if (final) throw this.syntax(`unterminated ${describeToken(s, i)}`, i) |
| 1590 | break |
| 1591 | } |
| 1592 | i = end |
| 1593 | } |
| 1594 | this.count(i) |
| 1595 | this.buf = "" |
| 1596 | if (i < n) { |
| 1597 | const rest = i === 0 ? s : s.slice(i) |
| 1598 | this.pending = [rest] |
| 1599 | this.pendingStart = this.base + i |
| 1600 | this.pendingLength = rest.length |
| 1601 | this.pendingAdded = 0 |
| 1602 | // Brings the scanner to the end of the incomplete token |
| 1603 | this.scanner.reset(S_START) |
| 1604 | this.scanner.scan(rest, 0) |
| 1605 | this.checkPending() |
| 1606 | } |
| 1607 | } |
no test coverage detected