Skip to content

Commit dbe4426

Browse files
JLHwungmathiasbynens
authored andcommitted
Generate the missing Unicode 1.1 Han character names
UnicodeData-1.1.5 uses one representative record and omits the compatibility ideographs. Generate individual formal names for the 20,902 unified and 302 compatibility ideographs listed in CJKXREF. Assisted-By: GPT-6 Issue: #110
1 parent e06c8bb commit dbe4426

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎scripts/parse-names.mjs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,21 @@ const parseNames = async (version) => {
144144
}
145145
}
146146

147+
if (version === '1.1.5') {
148+
// UnicodeData-1.1.5 has one representative Han record and omits the
149+
// compatibility ideographs. CJKXREF lists both complete ranges:
150+
// https://www.unicode.org/Public/1.1-Update/CJKXREF.TXT
151+
for (const [rangeName, start, end] of [
152+
['CJK Ideograph', 0x4e00, 0x9fa5],
153+
['CJK Compatibility Ideograph', 0xf900, 0xfa2d],
154+
]) {
155+
for (let cp = start; cp <= end; cp++) {
156+
const name = getRangeName(rangeName, cp);
157+
map[name] ??= regenerate();
158+
map[name].add(cp);
159+
}
160+
}
161+
}
147162
return map;
148163
};
149164

‎tests/legacy-names.mjs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { test } from 'node:test';
2+
import parseNames from '../scripts/parse-names.mjs';
3+
4+
test('Unicode 1.1.5 provides formal names for its complete Han repertoire', async (t) => {
5+
const names = await parseNames('1.1.5');
6+
for (const [cp, name] of [
7+
[0x4e00, 'CJK UNIFIED IDEOGRAPH-4E00'],
8+
[0x4e01, 'CJK UNIFIED IDEOGRAPH-4E01'],
9+
[0x9fa5, 'CJK UNIFIED IDEOGRAPH-9FA5'],
10+
[0xf900, 'CJK COMPATIBILITY IDEOGRAPH-F900'],
11+
[0xf901, 'CJK COMPATIBILITY IDEOGRAPH-F901'],
12+
[0xfa2d, 'CJK COMPATIBILITY IDEOGRAPH-FA2D'],
13+
]) {
14+
t.assert.deepEqual(names[name]?.toArray(), [cp], name);
15+
}
16+
t.assert.equal(
17+
Object.keys(names).filter((name) =>
18+
name.startsWith('CJK UNIFIED IDEOGRAPH-'),
19+
).length,
20+
20902,
21+
);
22+
t.assert.equal(
23+
Object.keys(names).filter((name) =>
24+
name.startsWith('CJK COMPATIBILITY IDEOGRAPH-'),
25+
).length,
26+
302,
27+
);
28+
t.assert.equal(names['CJK UNIFIED IDEOGRAPH-9FA6'], undefined);
29+
t.assert.equal(names['CJK COMPATIBILITY IDEOGRAPH-FA2E'], undefined);
30+
t.assert.equal(names['<CJK IDEOGRAPH REPRESENTATIVE>'], undefined);
31+
});

‎tests/tests.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
import { suite, test } from 'node:test';
55
import './parsers.mjs';
6+
import './legacy-names.mjs';
67
import './line-endings.mjs';
78
import resources from '../data/resources.mjs';
89

0 commit comments

Comments
 (0)