@@ -18,7 +18,8 @@ async function main() {
1818 const body = await response . text ( ) ;
1919
2020 const ranges = [ ] ;
21- const lines = [ ] ;
21+ const statuses = [ ] ;
22+ const mappings = [ ] ;
2223
2324 body . split ( "\n" ) . forEach ( l => {
2425 l = l . split ( "#" ) [ 0 ] ; // Remove comments
@@ -36,15 +37,16 @@ async function main() {
3637 cells [ 0 ] = [ start , end - start ] ;
3738 ranges . push ( cells . shift ( ) ) ;
3839
39- cells [ 0 ] = STATUS_MAPPING [ cells [ 0 ] ] ;
40- if ( cells [ 0 ] !== STATUS_MAPPING . mapped && cells [ 0 ] !== STATUS_MAPPING . deviation ) {
41- lines . push ( cells [ 0 ] ) ;
40+ const status = STATUS_MAPPING [ cells . shift ( ) ] ;
41+ statuses . push ( status ) ;
42+
43+ if ( status !== STATUS_MAPPING . mapped && status !== STATUS_MAPPING . deviation ) {
4244 return ;
4345 }
4446
45- if ( cells [ 1 ] !== undefined ) {
47+ if ( cells [ 0 ] !== undefined ) {
4648 // Parse replacement to int[] array
47- let replacement = cells [ 1 ] . split ( " " ) ;
49+ let replacement = cells [ 0 ] . split ( " " ) ;
4850 if ( replacement [ 0 ] === "" ) { // Empty array
4951 replacement = [ ] ;
5052 }
@@ -53,12 +55,10 @@ async function main() {
5355 return parseInt ( r , 16 ) ;
5456 } ) ;
5557
56- cells [ 1 ] = String . fromCodePoint ( ...replacement ) ;
58+ mappings . push ( String . fromCodePoint ( ...replacement ) ) ;
5759 } else {
5860 throw new Error ( "Unexpected" ) ;
5961 }
60-
61- lines . push ( cells . flat ( ) ) ;
6262 } ) ;
6363
6464 // We could drop valid chars, but those are only ~1000 ranges and
@@ -71,7 +71,7 @@ async function main() {
7171 last += range [ 0 ] ;
7272 }
7373
74- // Condense repeats of N consecutive [1, 0] in ranges to -N
74+ // Condense repeats of N consecutive [1, 0] in ranges to -N, flatten the rest
7575 const rangesCondensed = [ ] ;
7676 let repeats = 0 ;
7777 for ( const row of ranges ) {
@@ -85,13 +85,35 @@ async function main() {
8585 repeats = 0 ;
8686 }
8787
88- rangesCondensed . push ( row ) ;
88+ rangesCondensed . push ( ... row ) ;
8989 }
9090
9191 if ( repeats > 0 ) {
9292 rangesCondensed . push ( - repeats ) ;
93+ repeats = 0 ;
94+ }
95+
96+ // Condense repeats of N consecutive STATUS_MAPPING.mapped to -N
97+ const statusesCondensed = [ ] ;
98+ for ( const status of statuses ) {
99+ if ( status === STATUS_MAPPING . mapped ) {
100+ repeats ++ ;
101+ continue ;
102+ }
103+
104+ if ( repeats > 0 ) {
105+ statusesCondensed . push ( - repeats ) ;
106+ repeats = 0 ;
107+ }
108+
109+ statusesCondensed . push ( status ) ;
110+ }
111+
112+ if ( repeats > 0 ) {
113+ statusesCondensed . push ( - repeats ) ;
114+ repeats = 0 ;
93115 }
94116
95- const tablesRaw = [ rangesCondensed . flat ( ) , lines . flat ( ) ] ;
117+ const tablesRaw = [ rangesCondensed , statusesCondensed , mappings ] ;
96118 fs . writeFileSync ( path . resolve ( __dirname , "../lib/mappingTable.json" ) , JSON . stringify ( tablesRaw ) ) ;
97119}
0 commit comments