File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,6 +35,24 @@ const parseDecompositionMapping = async (version) => {
3535 return ;
3636 }
3737 const map = { } ;
38+ // UnicodeData represents all modern Hangul syllables as a range with empty
39+ // decomposition fields. Their canonical mappings are defined algorithmically:
40+ // https://www.unicode.org/versions/Unicode18.0.0/core-spec/chapter-3/#G56669
41+ const hangul = new Map ( ) ;
42+ for ( let syllable = 0xac00 ; syllable <= 0xd7a3 ; syllable ++ ) {
43+ const index = syllable - 0xac00 ;
44+ const trailing = index % 28 ;
45+ hangul . set (
46+ syllable ,
47+ trailing
48+ ? [ syllable - trailing , 0x11a7 + trailing ]
49+ : [
50+ 0x1100 + Math . floor ( index / 588 ) ,
51+ 0x1161 + ( Math . floor ( index / 28 ) % 21 ) ,
52+ ] ,
53+ ) ;
54+ }
55+ map . Canonical = hangul ;
3856 const lines = source . split ( '\n' ) ;
3957 for ( const line of lines ) {
4058 const trimmed = line . trim ( ) ;
Original file line number Diff line number Diff line change 1+ import { test } from 'node:test' ;
2+ import parseDecompositionMapping from '../scripts/parse-decomposition-mapping.mjs' ;
3+
4+ test ( 'Hangul has pairwise canonical decomposition mappings' , async ( t ) => {
5+ for ( const version of [ '2.0.14' , '3.2.0' , '18.0.0' ] ) {
6+ const { Canonical } = await parseDecompositionMapping ( version ) ;
7+ t . assert . deepEqual ( Canonical . get ( 0xac00 ) , [ 0x1100 , 0x1161 ] ) ;
8+ t . assert . deepEqual ( Canonical . get ( 0xac01 ) , [ 0xac00 , 0x11a8 ] ) ;
9+ t . assert . deepEqual ( Canonical . get ( 0xd7a3 ) , [ 0xd788 , 0x11c2 ] ) ;
10+ for ( let cp = 0xac00 ; cp <= 0xd7a3 ; cp ++ ) {
11+ t . assert . equal ( Canonical . get ( cp ) ?. length , 2 ) ;
12+ }
13+ }
14+ t . assert . equal ( await parseDecompositionMapping ( '1.1.5' ) , undefined ) ;
15+ } ) ;
Original file line number Diff line number Diff line change 11import { suite , test } from 'node:test' ;
2+ import './parsers.mjs' ;
23import resources from '../data/resources.mjs' ;
34
45const oldest = resources [ 0 ] . version ;
You can’t perform that action at this time.
0 commit comments