5
5
# code covering the core properties. Since this is a pretty rare event we
6
6
# just store this out-of-line and check the unicode.rs file into git.
7
7
#
8
- # The emitted code is "the minimum we think is necessary for libcore ", that
8
+ # The emitted code is "the minimum we think is necessary for libstd ", that
9
9
# is, to support basic operations of the compiler and "most nontrivial rust
10
10
# programs". It is not meant to be a complete implementation of unicode.
11
11
# For that we recommend you use a proper binding to libicu.
@@ -41,7 +41,7 @@ def load_unicode_data(f):
41
41
continue
42
42
[code , name , gencat , combine , bidi ,
43
43
decomp , deci , digit , num , mirror ,
44
- old , iso , upcase , lowcsae , titlecase ] = fields
44
+ old , iso , upcase , lowcase , titlecase ] = fields
45
45
46
46
code = int (code , 16 )
47
47
@@ -89,11 +89,9 @@ def load_unicode_data(f):
89
89
90
90
return (canon_decomp , compat_decomp , gencats , combines )
91
91
92
-
93
- def load_derived_core_properties (f ):
92
+ def load_properties (f , interestingprops ):
94
93
fetch (f )
95
- derivedprops = {}
96
- interestingprops = ["XID_Start" , "XID_Continue" , "Alphabetic" ]
94
+ props = {}
97
95
re1 = re .compile ("^([0-9A-F]+) +; (\w+)" )
98
96
re2 = re .compile ("^([0-9A-F]+)\.\.([0-9A-F]+) +; (\w+)" )
99
97
@@ -118,10 +116,10 @@ def load_derived_core_properties(f):
118
116
continue
119
117
d_lo = int (d_lo , 16 )
120
118
d_hi = int (d_hi , 16 )
121
- if prop not in derivedprops :
122
- derivedprops [prop ] = []
123
- derivedprops [prop ].append ((d_lo , d_hi ))
124
- return derivedprops
119
+ if prop not in props :
120
+ props [prop ] = []
121
+ props [prop ].append ((d_lo , d_hi ))
122
+ return props
125
123
126
124
def escape_char (c ):
127
125
if c <= 0xff :
@@ -144,7 +142,7 @@ def emit_bsearch_range_table(f):
144
142
use cmp::{Equal, Less, Greater};
145
143
use vec::ImmutableVector;
146
144
use option::None;
147
- (do r.bsearch |&(lo,hi)| {
145
+ r.bsearch( |&(lo,hi)| {
148
146
if lo <= c && c <= hi { Equal }
149
147
else if hi < c { Less }
150
148
else { Greater }
@@ -302,14 +300,14 @@ def emit_decomp_module(f, canon, compat, combine):
302
300
ix += 1
303
301
f .write ("\n ];\n " )
304
302
305
- f .write (" pub fn canonical(c: char, i: &fn( char) ) "
303
+ f .write (" pub fn canonical(c: char, i: | char| ) "
306
304
+ "{ d(c, i, false); }\n \n " )
307
- f .write (" pub fn compatibility(c: char, i: &fn( char) ) "
305
+ f .write (" pub fn compatibility(c: char, i: | char| ) "
308
306
+ "{ d(c, i, true); }\n \n " )
309
307
f .write (" pub fn canonical_combining_class(c: char) -> u8 {\n "
310
308
+ " bsearch_range_value_table(c, combining_class_table)\n "
311
309
+ " }\n \n " )
312
- f .write (" fn d(c: char, i: &fn( char) , k: bool) {\n " )
310
+ f .write (" fn d(c: char, i: | char| , k: bool) {\n " )
313
311
f .write (" use iter::Iterator;\n " );
314
312
315
313
f .write (" if c <= '\\ x7f' { i(c); return; }\n " )
@@ -376,5 +374,9 @@ def emit_decomp_module(f, canon, compat, combine):
376
374
377
375
emit_decomp_module (rf , canon_decomp , compat_decomp , combines )
378
376
379
- derived = load_derived_core_properties ("DerivedCoreProperties.txt" )
377
+ derived = load_properties ("DerivedCoreProperties.txt" ,
378
+ ["XID_Start" , "XID_Continue" , "Alphabetic" , "Lowercase" , "Uppercase" ])
380
379
emit_property_module (rf , "derived_property" , derived )
380
+
381
+ props = load_properties ("PropList.txt" , ["White_Space" ])
382
+ emit_property_module (rf , "property" , props )
0 commit comments