@@ -169,7 +169,7 @@ def emit_bsearch_range_table(f):
169
169
else if hi < c { Less }
170
170
else { Greater }
171
171
}) != None
172
- }\n \n
172
+ }\n
173
173
""" );
174
174
175
175
def emit_property_module (f , mod , tbl ):
@@ -193,11 +193,11 @@ def emit_property_module(f, mod, tbl):
193
193
f .write (" pub fn %s(c: char) -> bool {\n " % cat )
194
194
f .write (" super::bsearch_range_table(c, %s_table)\n " % cat )
195
195
f .write (" }\n \n " )
196
- f .write ("}\n " )
196
+ f .write ("}\n \n " )
197
197
198
198
199
199
def emit_conversions_module (f , lowerupper , upperlower ):
200
- f .write ("pub mod conversions {\n " )
200
+ f .write ("pub mod conversions {" )
201
201
f .write ("""
202
202
use cmp::{Equal, Less, Greater};
203
203
use slice::ImmutableVector;
@@ -225,13 +225,14 @@ def emit_conversions_module(f, lowerupper, upperlower):
225
225
else { Greater }
226
226
})
227
227
}
228
+
228
229
""" );
229
230
emit_caseconversion_table (f , "LuLl" , upperlower )
230
231
emit_caseconversion_table (f , "LlLu" , lowerupper )
231
232
f .write ("}\n " )
232
233
233
234
def emit_caseconversion_table (f , name , table ):
234
- f .write (" static %s_table : &'static [(char, char)] = &[\n " % name )
235
+ f .write (" static %s_table : &'static [(char, char)] = &[\n " % name )
235
236
sorted_table = sorted (table .iteritems (), key = operator .itemgetter (0 ))
236
237
ix = 0
237
238
for key , value in sorted_table :
@@ -255,7 +256,7 @@ def format_table_content(f, content, indent):
255
256
line = " " * indent + chunk
256
257
f .write (line )
257
258
258
- def emit_decomp_module (f , canon , compat , combine ):
259
+ def emit_core_decomp_module (f , canon , compat ):
259
260
canon_keys = canon .keys ()
260
261
canon_keys .sort ()
261
262
@@ -279,23 +280,6 @@ def emit_decomp_module(f, canon, compat, combine):
279
280
}
280
281
None => None
281
282
}
282
- }\n
283
- """ )
284
-
285
- f .write ("""
286
- fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 {
287
- use cmp::{Equal, Less, Greater};
288
- match r.bsearch(|&(lo, hi, _)| {
289
- if lo <= c && c <= hi { Equal }
290
- else if hi < c { Less }
291
- else { Greater }
292
- }) {
293
- Some(idx) => {
294
- let (_, _, result) = r[idx];
295
- result
296
- }
297
- None => 0
298
- }
299
283
}\n \n
300
284
""" )
301
285
@@ -337,21 +321,10 @@ def emit_decomp_module(f, canon, compat, combine):
337
321
format_table_content (f , data , 8 )
338
322
f .write ("\n ];\n \n " )
339
323
340
- f .write (" static combining_class_table : &'static [(char, char, u8)] = &[\n " )
341
- ix = 0
342
- for pair in combine :
343
- f .write (ch_prefix (ix ))
344
- f .write ("(%s, %s, %s)" % (escape_char (pair [0 ]), escape_char (pair [1 ]), pair [2 ]))
345
- ix += 1
346
- f .write ("\n ];\n " )
347
-
348
324
f .write (" pub fn canonical(c: char, i: |char|) "
349
325
+ "{ d(c, i, false); }\n \n " )
350
326
f .write (" pub fn compatibility(c: char, i: |char|) "
351
327
+ "{ d(c, i, true); }\n \n " )
352
- f .write (" pub fn canonical_combining_class(c: char) -> u8 {\n "
353
- + " bsearch_range_value_table(c, combining_class_table)\n "
354
- + " }\n \n " )
355
328
f .write (" fn d(c: char, i: |char|, k: bool) {\n " )
356
329
f .write (" use iter::Iterator;\n " );
357
330
@@ -389,17 +362,43 @@ def emit_decomp_module(f, canon, compat, combine):
389
362
f .write (" }\n " )
390
363
f .write ("}\n \n " )
391
364
392
- r = "unicode.rs"
393
- for i in [r ]:
394
- if os .path .exists (i ):
395
- os .remove (i );
396
- rf = open (r , "w" )
365
+ def emit_std_decomp_module (f , combine ):
366
+ f .write ("pub mod decompose {\n " );
367
+ f .write (" use option::{Some, None};\n " );
368
+ f .write (" use slice::ImmutableVector;\n " );
397
369
398
- (canon_decomp , compat_decomp , gencats ,
399
- combines , lowerupper , upperlower ) = load_unicode_data ("UnicodeData.txt" )
370
+ f .write ("""
371
+ fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 {
372
+ use cmp::{Equal, Less, Greater};
373
+ match r.bsearch(|&(lo, hi, _)| {
374
+ if lo <= c && c <= hi { Equal }
375
+ else if hi < c { Less }
376
+ else { Greater }
377
+ }) {
378
+ Some(idx) => {
379
+ let (_, _, result) = r[idx];
380
+ result
381
+ }
382
+ None => 0
383
+ }
384
+ }\n \n
385
+ """ )
386
+
387
+ f .write (" static combining_class_table : &'static [(char, char, u8)] = &[\n " )
388
+ ix = 0
389
+ for pair in combine :
390
+ f .write (ch_prefix (ix ))
391
+ f .write ("(%s, %s, %s)" % (escape_char (pair [0 ]), escape_char (pair [1 ]), pair [2 ]))
392
+ ix += 1
393
+ f .write ("\n ];\n \n " )
400
394
401
- # Preamble
402
- rf .write ('''// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
395
+ f .write (" pub fn canonical_combining_class(c: char) -> u8 {\n "
396
+ + " bsearch_range_value_table(c, combining_class_table)\n "
397
+ + " }\n " )
398
+ f .write ("}\n " )
399
+
400
+
401
+ preamble = '''// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
403
402
// file at the top-level directory of this distribution and at
404
403
// http://rust-lang.org/COPYRIGHT.
405
404
//
@@ -409,23 +408,45 @@ def emit_decomp_module(f, canon, compat, combine):
409
408
// option. This file may not be copied, modified, or distributed
410
409
// except according to those terms.
411
410
412
- // The following code was generated by "src/etc/unicode.py"
411
+ // NOTE: The following code was generated by "src/etc/unicode.py", do not edit directly
412
+
413
+ #![allow(missing_doc, non_uppercase_statics)]
414
+
415
+ '''
416
+
417
+ (canon_decomp , compat_decomp , gencats ,
418
+ combines , lowerupper , upperlower ) = load_unicode_data ("UnicodeData.txt" )
419
+
420
+ def gen_core_unicode ():
421
+ r = "core_unicode.rs"
422
+ if os .path .exists (r ):
423
+ os .remove (r );
424
+ with open (r , "w" ) as rf :
425
+ # Preamble
426
+ rf .write (preamble )
413
427
414
- #![allow(missing_doc)]
415
- #![allow(non_uppercase_statics)]
428
+ emit_bsearch_range_table ( rf );
429
+ emit_property_module ( rf , "general_category" , gencats )
416
430
417
- ''' )
431
+ emit_core_decomp_module ( rf , canon_decomp , compat_decomp )
418
432
419
- emit_bsearch_range_table ( rf );
420
- emit_property_module ( rf , "general_category " , gencats )
433
+ derived = load_properties ( "DerivedCoreProperties.txt" ,
434
+ [ "XID_Start" , "XID_Continue " , "Alphabetic" , "Lowercase" , "Uppercase" ] )
421
435
422
- emit_decomp_module (rf , canon_decomp , compat_decomp , combines )
436
+ emit_property_module (rf , "derived_property" , derived )
423
437
424
- derived = load_properties ("DerivedCoreProperties.txt" ,
425
- ["XID_Start" , "XID_Continue" , "Alphabetic" , "Lowercase" , "Uppercase" ])
438
+ props = load_properties ("PropList.txt" , ["White_Space" ])
439
+ emit_property_module (rf , "property" , props )
440
+ emit_conversions_module (rf , lowerupper , upperlower )
426
441
427
- emit_property_module (rf , "derived_property" , derived )
442
+ def gen_std_unicode ():
443
+ r = "std_unicode.rs"
444
+ if os .path .exists (r ):
445
+ os .remove (r );
446
+ with open (r , "w" ) as rf :
447
+ # Preamble
448
+ rf .write (preamble )
449
+ emit_std_decomp_module (rf , combines )
428
450
429
- props = load_properties ("PropList.txt" , ["White_Space" ])
430
- emit_property_module (rf , "property" , props )
431
- emit_conversions_module (rf , lowerupper , upperlower )
451
+ gen_core_unicode ()
452
+ gen_std_unicode ()
0 commit comments