1
1
const xregexp = require ( 'xregexp' ) ;
2
2
3
- const names = require ( './unicode-data/names.js' ) ;
3
+ const ucd = require ( 'nqp-unicode-data' ) ;
4
+
4
5
const core = require ( './core.js' ) ;
5
6
6
7
//TODO - the regexes should be tweaked to match full graphemes instead
@@ -10,19 +11,14 @@ function mangled(name) {
10
11
return name . toLowerCase ( name ) . replace ( / _ / g, '' ) ;
11
12
}
12
13
13
- const propIdToNames = { } ;
14
- for ( const propName in names . props ) {
15
- const propId = names . props [ propName ] ;
16
- if ( ! propIdToNames [ propId ] ) propIdToNames [ propId ] = propIdToNames [ propId ] || [ ] ;
17
- propIdToNames [ propId ] . push ( propName ) ;
18
- }
19
14
20
15
21
16
function addProp ( propName , builder ) {
22
- const propId = names . props [ propName ] ;
17
+ const propId = ucd . propId ( propName ) ;
18
+
23
19
const match = builder ( true ) ;
24
20
const do_not_match = builder ( false ) ;
25
- for ( const alias of propIdToNames [ propId ] ) {
21
+ for ( const alias of ucd . propIdToNames ( propId ) ) {
26
22
exports [ 'uniprop_' + mangled ( alias ) ] = match ;
27
23
exports [ 'uniprop_not_' + mangled ( alias ) ] = do_not_match ;
28
24
}
@@ -55,7 +51,7 @@ addExtraProp('ascii', match => matchClass(match, 'ASCII'));
55
51
addExtraProp ( 'any' , match => matchClass ( match , 'Any' ) ) ;
56
52
57
53
function addPropValueProps ( propName , builder , filter , extraMangle ) {
58
- for ( const propValue of names . propValues [ names . props [ propName ] ] ) {
54
+ for ( const propValue of ucd . propValues ( ucd . propId ( propName ) ) ) {
59
55
if ( ! filter ( propValue [ 0 ] ) ) continue ;
60
56
for ( const alias of propValue ) {
61
57
const mangledAlias = mangled ( extraMangle ? extraMangle ( alias ) : alias ) ;
@@ -81,7 +77,7 @@ addPropValueProps('General_Category',
81
77
82
78
function categoriesToRegex ( categories ) {
83
79
return categories ? categories . map (
84
- category => names . regexes [ names . props [ category ] ] || '\\p{' + category + '}'
80
+ category => ucd . regex ( ucd . propId ( category ) ) || '\\p{' + category + '}'
85
81
) . join ( '|' ) : '' ;
86
82
}
87
83
@@ -103,16 +99,13 @@ const matchLC = match => matchDerived(match, ['Ll', 'Lu', 'Lt']);
103
99
addExtraProp ( 'LC' , matchLC ) ;
104
100
addExtraProp ( 'Cased_Letter' , matchLC ) ;
105
101
106
- const UnicodeTrie = require ( 'unicode-trie' )
107
- const fs = require ( 'fs' )
108
102
109
103
const nativeArgs = require ( './native-args.js' ) ;
110
104
const NativeStrArg = nativeArgs . NativeStrArg ;
111
105
112
- const numericTypeData = new UnicodeTrie ( fs . readFileSync ( __dirname + '/unicode-data/NumericType.trie' ) ) ;
113
- const bidiClassData = new UnicodeTrie ( fs . readFileSync ( __dirname + '/unicode-data/BidiClass.trie' ) ) ;
114
- const numericValueData = new UnicodeTrie ( fs . readFileSync ( __dirname + '/unicode-data/NumericValue.trie' ) ) ;
115
-
106
+ const numericTypeData = ucd . propTrie ( 'NumericType' ) ;
107
+ const bidiClassData = ucd . propTrie ( 'BidiClass' ) ;
108
+ const numericValueData = ucd . propTrie ( 'NumericValue' ) ;
116
109
117
110
function delegateAccepts ( shouldMatch , ctx , cursor , obj , code , value ) {
118
111
const result = cursor [ '!DELEGATE_ACCEPTS' ] ( ctx , null , cursor , obj , new NativeStrArg ( value ) ) . $$getInt ( ) ;
@@ -125,13 +118,13 @@ function delegateAccepts(shouldMatch, ctx, cursor, obj, code, value) {
125
118
}
126
119
127
120
function propWithArgs ( shouldMatch , trie , propName , longNames ) {
128
- const propId = names . props [ propName ] ;
121
+ const propId = ucd . propId ( propName ) ;
129
122
return function ( ctx , cursor , target , offset , obj ) {
130
123
const code = target . codePointAt ( offset ) ;
131
124
if ( code === undefined ) return - 1 ;
132
125
const propValueId = trie . get ( code ) ;
133
126
134
- let valueName = names . propValues [ propId ] [ propValueId - 1 ] [ longNames ? 1 : 0 ] ;
127
+ let valueName = ucd . propValues ( propId ) [ propValueId - 1 ] [ longNames ? 1 : 0 ] ;
135
128
136
129
return delegateAccepts ( shouldMatch , ctx , cursor , obj , code , valueName ) ;
137
130
} ;
@@ -185,17 +178,17 @@ function matchRegex(shouldMatch, regexString) {
185
178
} ;
186
179
}
187
180
188
- for ( const propId in names . regexes ) {
189
- const match = matchRegex ( true , names . regexes [ propId ] ) ;
190
- const negatedMatch = matchRegex ( false , names . regexes [ propId ] ) ;
191
- for ( const propName of propIdToNames [ propId ] ) {
181
+ for ( const propId of ucd . propIdsWithRegexes ( ) ) {
182
+ const match = matchRegex ( true , ucd . regex ( propId ) ) ;
183
+ const negatedMatch = matchRegex ( false , ucd . regex ( propId ) ) ;
184
+ for ( const propName of ucd . propIdToNames ( propId ) ) {
192
185
exports [ 'uniprop_' + mangled ( propName ) ] = match ;
193
186
exports [ 'uniprop_not_' + mangled ( propName ) ] = negatedMatch ;
194
187
}
195
188
}
196
189
197
190
198
- const mathRegex = names . regexes [ names . props . Other_Math ] + '|\\p{Sm}' ;
191
+ const mathRegex = ucd . regex ( ucd . propId ( ' Other_Math' ) ) + '|\\p{Sm}' ;
199
192
addProp ( 'Math' , match => matchRegex ( match , mathRegex ) ) ;
200
193
201
194
addExtraProp ( 'Assigned' , match => matchRegex ( true , match ? '\\P{Cn}' : '\\p{Cn}' ) ) ;
0 commit comments