From 43f26e5b23c6bf2d0e7d72ceeb9c02b2ceb7b608 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 21 Apr 2024 21:16:12 +0200 Subject: unicode: More results; aliases --- modules/unicode/aliases.txt | 3 +++ modules/unicode/unicode.js | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 modules/unicode/aliases.txt (limited to 'modules/unicode') diff --git a/modules/unicode/aliases.txt b/modules/unicode/aliases.txt new file mode 100644 index 0000000..ea23cab --- /dev/null +++ b/modules/unicode/aliases.txt @@ -0,0 +1,3 @@ +0x039B lambda +0x03BB lambda +0x2218 composition diff --git a/modules/unicode/unicode.js b/modules/unicode/unicode.js index ab8ad53..4b313fc 100644 --- a/modules/unicode/unicode.js +++ b/modules/unicode/unicode.js @@ -24,6 +24,8 @@ const fTITLECASE = 14; let db = new Map(); // ranges: [{name: String, first: int, last: int}] let ranges = []; +// aliases: [{name: String, code: int}] +let aliases = []; function importDatabase(csv) { // clear the database if necessary @@ -56,6 +58,17 @@ function importDatabase(csv) { } } +function importAliases(lines) { + aliases = []; + for (const line of lines.split("\n")) { + const idx = line.indexOf(" "); + if (idx == -1) continue; + const num = parseInt(line.slice(0, idx)); + const descr = line.slice(idx + 1).toUpperCase(); + aliases.push({name: descr, code: num}); + } +} + function lookupCode(codepoint) { for (const range of ranges) { if (range.first <= codepoint && codepoint <= range.last) { @@ -75,7 +88,14 @@ function searchDescription(text) { for (const row of db.values()) { if (row[fNAME].includes(text)) { result.push(row); - if (result.length >= 200) break; + if (result.length >= 500) return result; + } + } + + for (const row of aliases) { + if (row.name.includes(text)) { + result.push(db.get(row.code)); + if (result.length >= 500) return result; } } @@ -123,6 +143,8 @@ module.exports = function (app, io, moddir) { throw new Error("UnicodeData.txt doesn't exist! Be sure to run ./install_prepare.sh"); } + importAliases(fs.readFileSync(path.join(moddir, "aliases.txt")).toString()); + app.get("/unicode", (req, res) => { res.sendFile(path.join(moddir, "index.html")); }); -- cgit v1.2.3-70-g09d2