diff options
Diffstat (limited to 'modules/unicode/unicode.js')
-rw-r--r-- | modules/unicode/unicode.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/modules/unicode/unicode.js b/modules/unicode/unicode.js index d8ba227..a937796 100644 --- a/modules/unicode/unicode.js +++ b/modules/unicode/unicode.js @@ -82,6 +82,24 @@ function searchDescription(text) { return result; } +function recogniseIndex(text) { + let m; + + m = text.match(/^([0-9]+)$/); // 1234 + if (m) return lookupCode(parseInt(m[1], 10)); + + m = text.match(/^(?:0[Xx]|[Uu]\+)([0-9a-fA-F]+)$/); // 0x34ab / U+34ab + if (m) return lookupCode(parseInt(m[1], 16)); + + m = text.match(/^&#([0-9]+);$/); // Ӓ + if (m) return lookupCode(parseInt(m[1], 10)); + + m = text.match(/^&#[Xx]([0-9a-fA-F]+);$/); // 㒫 + if (m) return lookupCode(parseInt(m[1], 16)); + + return null; +} + module.exports = function (app, io, moddir) { const dataFilePath = path.join(moddir, "UnicodeData.txt"); if (fs.existsSync(dataFilePath)) { @@ -120,6 +138,7 @@ module.exports = function (app, io, moddir) { } res.json({ + index: recogniseIndex(req.params.query) || undefined, chars: chars, search: searchDescription(req.params.query), }); |