Skip to content

Commit

Permalink
refactor: Call replaceCodePoint in tokenizer (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 authored Apr 23, 2022
1 parent 7b8a2f3 commit 8a785b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/Parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Tokenizer, { Callbacks, QuoteType } from "./Tokenizer.js";
import { decodeCodePoint } from "entities/lib/decode.js";
import { fromCodePoint } from "entities/lib/decode.js";

const formTags = new Set([
"input",
Expand Down Expand Up @@ -258,7 +258,7 @@ export class Parser implements Callbacks {
*/
const idx = this.tokenizer.getSectionStart();
this.endIndex = idx - 1;
this.cbs.ontext?.(decodeCodePoint(cp));
this.cbs.ontext?.(fromCodePoint(cp));
this.startIndex = idx;
}

Expand Down Expand Up @@ -420,7 +420,7 @@ export class Parser implements Callbacks {

/** @internal */
onattribentity(cp: number): void {
this.attribvalue += decodeCodePoint(cp);
this.attribvalue += fromCodePoint(cp);
}

/** @internal */
Expand Down
18 changes: 4 additions & 14 deletions src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
xmlDecodeTree,
BinTrieFlags,
determineBranch,
replaceCodePoint,
} from "entities/lib/decode.js";

const enum CharCodes {
Expand Down Expand Up @@ -707,19 +708,8 @@ export default class Tokenizer {
this.emitCodePoint(this.entityTrie[this.entityResult + 1]);
break;
case 3: {
const first = this.entityTrie[this.entityResult + 1];
const second = this.entityTrie[this.entityResult + 2];

// If this is a surrogate pair, combine the code points.
if (first >= 0xd8_00 && first <= 0xdf_ff) {
this.emitCodePoint(
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
(first - 0xd8_00) * 0x4_00 + second + 0x24_00
);
} else {
this.emitCodePoint(first);
this.emitCodePoint(second);
}
this.emitCodePoint(this.entityTrie[this.entityResult + 1]);
this.emitCodePoint(this.entityTrie[this.entityResult + 2]);
}
}
}
Expand All @@ -746,7 +736,7 @@ export default class Tokenizer {
}

this.sectionStart = this.index + Number(strict);
this.emitCodePoint(this.entityResult);
this.emitCodePoint(replaceCodePoint(this.entityResult));
}
this.state = this.baseState;
}
Expand Down

0 comments on commit 8a785b8

Please sign in to comment.