@@ -7,37 +7,26 @@ const parseSpecialCasing = async (version) => {
77 return ;
88 }
99 for ( const line of source . split ( '\n' ) ) {
10- if ( line === '' || line . startsWith ( '#' ) ) {
10+ const record = line . split ( '#' ) [ 0 ] . trim ( ) ;
11+ if ( ! record ) {
1112 continue ;
1213 }
13- const data = line . slice ( 0 , line . lastIndexOf ( '#' ) ) . split ( '; ' ) ;
14+ const data = record . split ( ';' ) . map ( ( field ) => field . trim ( ) ) ;
1415 const from = parseInt ( data [ 0 ] , 16 ) ;
15-
16- const lowercase =
17- data [ 1 ] === ''
18- ? [ ]
19- : data [ 1 ] . split ( ' ' ) . map ( ( codePoint ) => {
20- return parseInt ( codePoint , 16 ) ;
21- } ) ; // Note: this could be zero or two characters!
22- const titlecase =
23- data [ 2 ] === ''
24- ? [ ]
25- : data [ 2 ] . split ( ' ' ) . map ( ( codePoint ) => {
26- return parseInt ( codePoint , 16 ) ;
27- } ) ; // Note: this could be zero or two characters!
28- const uppercase =
29- data [ 3 ] === ''
30- ? [ ]
31- : data [ 3 ] . split ( ' ' ) . map ( ( codePoint ) => {
32- return parseInt ( codePoint , 16 ) ;
33- } ) ; // Note: this could be zero or two characters!
16+ const [ lowercase , titlecase , uppercase ] = data
17+ . slice ( 1 , 4 )
18+ . map ( ( mapping ) =>
19+ mapping === ''
20+ ? [ ]
21+ : mapping . split ( / \s + / ) . map ( ( codePoint ) => parseInt ( codePoint , 16 ) ) ,
22+ ) ;
3423
3524 // Conditions can contain a language ID defined by BCP 47 and casing contexts
3625 // defined in Table 3-17 Context Specification for Casing:
3726 // https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-3/#G54277
3827 // Because the language ID may contain `-`, we let `--` be the separator
3928 // between the language ID and the casing contexts.
40- const conditions = data [ 4 ] . trim ( ) . replaceAll ( ' ' , '--' ) ;
29+ const conditions = ( data [ 4 ] ?? '' ) . replace ( / \s + / g , '--' ) ;
4130 const storageKeyPostfix = conditions ? '--' + conditions : '' ;
4231 specialCasingMap [ 'Lowercase' + storageKeyPostfix ] ??= new Map ( ) ;
4332 specialCasingMap [ 'Lowercase' + storageKeyPostfix ] . set ( from , lowercase ) ;
0 commit comments