Skip to content

Commit 0f1ea67

Browse files
committed
JSON escape, URI/URIComponent
1 parent 63b3a64 commit 0f1ea67

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

bin/ucd_to_json.mts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ import { fileURLToPath } from "url";
88
const __filename = fileURLToPath(import.meta.url);
99
const __dirname = path.dirname(__filename);
1010

11+
// from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#escape_sequences
12+
const jsonEscape: { [key: string]: string } = {
13+
"0000": "\\0",
14+
"0027": "\\'",
15+
"0022": '\\"',
16+
"005C": "\\\\",
17+
"000A": "\\n",
18+
"000D": "\\r",
19+
"000B": "\\v",
20+
"0009": "\\t",
21+
"0008": "\\b",
22+
"000c": "\\f",
23+
};
24+
25+
1126
type SearchEntry = {
1227
code: string;
1328
name: string;
@@ -235,6 +250,19 @@ async function main() {
235250
console.log(`INFO: name-alias data: ${JSON.stringify(charData['name-alias'])}`);
236251
}
237252

253+
const jse = jsonEscape[charData.cp];
254+
if (jse) {
255+
notes.push(`JSON escape: '${jse}'`);
256+
}
257+
258+
const str = String.fromCodePoint(parseInt(charData.cp, 16));
259+
if (encodeURI(str) == str) {
260+
tags.push(`URI-safe`);
261+
}
262+
if (encodeURIComponent(str) == str) {
263+
tags.push(`URIComponent-safe`);
264+
}
265+
238266
entries.push({
239267
code: charData.cp,
240268
name: name || "(no name)",

0 commit comments

Comments
 (0)