| 1635 | // Replaces references and normalizes line endings, or attribute whitespace. |
| 1636 | // `whitespace` is false when `raw` has nothing to normalize. |
| 1637 | private decodeText(raw: string, offset: number, attribute: boolean, whitespace: boolean): string { |
| 1638 | let out = "" |
| 1639 | let k = 0 |
| 1640 | while (true) { |
| 1641 | const amp = raw.indexOf("&", k) |
| 1642 | const literal = raw.slice(k, amp === -1 ? raw.length : amp) |
| 1643 | out += !whitespace ? literal : attribute ? normalizeAttribute(literal) : normalizeLines(literal) |
| 1644 | if (amp === -1) return out |
| 1645 | const semicolon = raw.indexOf(";", amp + 1) |
| 1646 | if (semicolon === -1) throw this.syntax("unterminated reference", offset + amp) |
| 1647 | out += this.reference(raw, amp, semicolon, offset) |
| 1648 | k = semicolon + 1 |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | // Decodes the reference `raw[amp, semicolon]` |
| 1653 | private reference(raw: string, amp: number, semicolon: number, offset: number): string { |