@@ -3,15 +3,13 @@ import * as path from "path";
33import { CharSet } from "../src/char-set" ;
44import { printRanges } from "./util" ;
55
6+ const caseFoldingCommon : ReadonlyMap < number , number > = require ( "@unicode/unicode-13.0.0/Case_Folding/C/code-points" ) ;
7+ const caseFoldingSimple : ReadonlyMap < number , number > = require ( "@unicode/unicode-13.0.0/Case_Folding/S/code-points" ) ;
68
7- const CaseFoldingCommon : ReadonlyMap < number , number > = require ( "@unicode/unicode-13.0.0/Case_Folding/C/code-points ") ;
8- const CaseFoldingSimple : ReadonlyMap < number , number > = require ( "@ unicode/unicode-13.0.0/Case_Folding/S/code-points ") ;
9+ createCaseFoldingFile ( canonicalizeIgnoreCaseUTF16 , 0xffff , "UTF16" , "utf16-case-folding.ts ") ;
10+ createCaseFoldingFile ( canonicalizeIgnoreCaseUnicode , 0x10ffff , "Unicode" , " unicode/case-folding.ts ") ;
911
10-
11- createCaseFoldingFile ( UTF16CanonicalizeIgnoreCase , 0xFFFF , "UTF16" , "utf16-case-folding.ts" ) ;
12- createCaseFoldingFile ( UnicodeCanonicalizeIgnoreCase , 0x10FFFF , "Unicode" , "unicode/case-folding.ts" ) ;
13-
14- function UTF16CanonicalizeIgnoreCase ( ch : number ) : number {
12+ function canonicalizeIgnoreCaseUTF16 ( ch : number ) : number {
1513 // https://tc39.es/ecma262/#sec-runtime-semantics-canonicalize-ch
1614
1715 const s = String . fromCharCode ( ch ) ;
@@ -26,14 +24,14 @@ function UTF16CanonicalizeIgnoreCase(ch: number): number {
2624 return cu ;
2725}
2826
29- function UnicodeCanonicalizeIgnoreCase ( ch : number ) : number {
27+ function canonicalizeIgnoreCaseUnicode ( ch : number ) : number {
3028 // https://tc39.es/ecma262/#sec-runtime-semantics-canonicalize-ch
3129
32- let mapping = CaseFoldingCommon . get ( ch ) ;
30+ let mapping = caseFoldingCommon . get ( ch ) ;
3331 if ( mapping !== undefined ) {
3432 return mapping ;
3533 }
36- mapping = CaseFoldingSimple . get ( ch ) ;
34+ mapping = caseFoldingSimple . get ( ch ) ;
3735 if ( mapping !== undefined ) {
3836 return mapping ;
3937 }
@@ -47,13 +45,12 @@ function createCaseFoldingFile(
4745 variablePrefix : string ,
4846 filename : string
4947) : void {
50-
5148 const canonicalizeMapping = new Map < number , number [ ] > ( ) ;
5249 for ( let ch = 0 ; ch <= maxCharacter ; ch ++ ) {
5350 const c = canonicalize ( ch ) ;
5451 let list = canonicalizeMapping . get ( c ) ;
5552 if ( list === undefined ) {
56- canonicalizeMapping . set ( c , list = [ ] ) ;
53+ canonicalizeMapping . set ( c , ( list = [ ] ) ) ;
5754 }
5855 list . push ( ch ) ;
5956 }
@@ -66,18 +63,21 @@ function createCaseFoldingFile(
6663 } ) ;
6764
6865 let count = 0 ;
69- const CASE_VARYING = CharSet . fromCharacters ( maxCharacter , function * ( ) {
70- for ( let i = 0 ; i < maxCharacter ; i ++ ) {
71- const fold = caseFolding [ i ] ;
72- if ( fold . indexOf ( i ) === - 1 ) {
73- throw new Error ( `The case folding of ${ i } does not include itself.` ) ;
74- }
75- if ( fold . length > 1 ) {
76- count ++ ;
77- yield i ;
66+ const CASE_VARYING = CharSet . fromCharacters (
67+ maxCharacter ,
68+ ( function * ( ) {
69+ for ( let i = 0 ; i < maxCharacter ; i ++ ) {
70+ const fold = caseFolding [ i ] ;
71+ if ( fold . indexOf ( i ) === - 1 ) {
72+ throw new Error ( `The case folding of ${ i } does not include itself.` ) ;
73+ }
74+ if ( fold . length > 1 ) {
75+ count ++ ;
76+ yield i ;
77+ }
7878 }
79- }
80- } ( ) ) ;
79+ } ) ( )
80+ ) ;
8181
8282 const map : Record < number , number [ ] > = { } ;
8383 caseFolding . forEach ( ( fold , i ) => {
@@ -88,7 +88,6 @@ function createCaseFoldingFile(
8888
8989 console . log ( `${ variablePrefix } : ${ count } characters vary in case` ) ;
9090
91-
9291 const code = `/* eslint-disable */
9392
9493// DO NOT EDIT!
@@ -100,17 +99,19 @@ import { CharSet } from "${"../".repeat(filename.split(/\//g).length)}char-set";
10099/**
101100 * A character set of all characters that have at least one case variation.
102101 */
103- export const ${ variablePrefix } CaseVarying: CharSet = CharSet.empty(${ maxCharacter } ).union(${ printRanges ( CASE_VARYING . ranges )
104- } );
102+ export const ${ variablePrefix } CaseVarying: CharSet = CharSet.empty(${ maxCharacter } ).union(${ printRanges (
103+ CASE_VARYING . ranges
104+ ) } );
105105
106106/**
107107 * A map for a given character to all it case variations. The list of case variations also includes the key character
108108 * itself.
109109 *
110110 * If the given character do not have case variations, it will not be part of this map.
111111 */
112- export const ${ variablePrefix } CaseFolding: Readonly<Record<number, readonly number[]>> = JSON.parse(${ JSON . stringify ( JSON . stringify ( map ) )
113- } );
112+ export const ${ variablePrefix } CaseFolding: Readonly<Record<number, readonly number[]>> = JSON.parse(${ JSON . stringify (
113+ JSON . stringify ( map )
114+ ) } );
114115` ;
115116
116117 fs . writeFileSync ( path . join ( __dirname , "../src/js" , filename ) , code , "utf-8" ) ;
0 commit comments