@@ -26,15 +26,11 @@ def fetch(f):
26
26
def load_unicode_data (f ):
27
27
fetch (f )
28
28
gencats = {}
29
- combines = []
30
29
canon_decomp = {}
31
30
compat_decomp = {}
32
31
curr_cat = ""
33
- curr_combine = ""
34
32
c_lo = 0
35
33
c_hi = 0
36
- com_lo = 0
37
- com_hi = 0
38
34
for line in fileinput .input (f ):
39
35
fields = line .split (";" )
40
36
if len (fields ) != 15 :
@@ -73,21 +69,7 @@ def load_unicode_data(f):
73
69
c_lo = code
74
70
c_hi = code
75
71
76
- if curr_combine == "" :
77
- curr_combine = combine
78
- com_lo = code
79
- com_hi = code
80
-
81
- if curr_combine == combine :
82
- com_hi = code
83
- else :
84
- if curr_combine != "0" :
85
- combines .append ((com_lo , com_hi , curr_combine ))
86
- curr_combine = combine
87
- com_lo = code
88
- com_hi = code
89
-
90
- return (canon_decomp , compat_decomp , gencats , combines )
72
+ return (canon_decomp , compat_decomp , gencats )
91
73
92
74
93
75
def load_derived_core_properties (f ):
@@ -196,149 +178,50 @@ def emit_property_module_old(f, mod, tbl):
196
178
f .write (" }\n \n " )
197
179
f .write ("}\n " )
198
180
199
- def format_table_content (f , content , indent ):
200
- line = " " * indent
201
- first = True
202
- for chunk in content .split ("," ):
203
- if len (line ) + len (chunk ) < 98 :
204
- if first :
205
- line += chunk
206
- else :
207
- line += ", " + chunk
208
- first = False
209
- else :
210
- f .write (line + ",\n " )
211
- line = " " * indent + chunk
212
- f .write (line )
213
-
214
- def emit_decomp_module (f , canon , compat , combine ):
181
+ def emit_decomp_module (f , canon , compat ):
215
182
canon_keys = canon .keys ()
216
183
canon_keys .sort ()
217
184
218
185
compat_keys = compat .keys ()
219
186
compat_keys .sort ()
220
- f .write ("pub mod decompose {\n " );
221
- f .write (" use option::Option;\n " );
222
- f .write (" use option::{Some, None};\n " );
223
- f .write (" use vec::ImmutableVector;\n " );
224
- f .write ("""
225
- fn bsearch_table(c: char, r: &'static [(char, &'static [char])]) -> Option<&'static [char]> {
226
- use cmp::{Equal, Less, Greater};
227
- match r.bsearch(|&(val, _)| {
228
- if c == val { Equal }
229
- else if val < c { Less }
230
- else { Greater }
231
- }) {
232
- Some(idx) => {
233
- let (_, result) = r[idx];
234
- Some(result)
235
- }
236
- None => None
237
- }
238
- }\n
239
- """ )
187
+ f .write ("mod decompose {\n \n " );
188
+ f .write (" export canonical, compatibility;\n \n " )
189
+ f .write (" fn canonical(c: char, i: block(char)) "
190
+ + "{ d(c, i, false); }\n \n " )
191
+ f .write (" fn compatibility(c: char, i: block(char)) "
192
+ + "{ d(c, i, true); }\n \n " )
193
+ f .write (" fn d(c: char, i: block(char), k: bool) {\n " )
240
194
241
- f .write ("""
242
- fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 {
243
- use cmp::{Equal, Less, Greater};
244
- match r.bsearch(|&(lo, hi, _)| {
245
- if lo <= c && c <= hi { Equal }
246
- else if hi < c { Less }
247
- else { Greater }
248
- }) {
249
- Some(idx) => {
250
- let (_, _, result) = r[idx];
251
- result
252
- }
253
- None => 0
254
- }
255
- }\n \n
256
- """ )
195
+ f .write (" if c <= '\\ x7f' { i(c); ret; }\n " )
257
196
258
- f .write (" // Canonical decompositions\n " )
259
- f .write (" static canonical_table : &'static [(char, &'static [char])] = &[\n " )
260
- data = ""
261
- first = True
197
+ # First check the canonical decompositions
198
+ f .write (" // Canonical decomposition\n " )
199
+ f .write (" alt c {\n " )
262
200
for char in canon_keys :
263
- if not first :
264
- data += ","
265
- first = False
266
- data += "(%s,&[" % escape_char (char )
267
- first2 = True
201
+ f .write (" %s {\n " % escape_char (char ))
268
202
for d in canon [char ]:
269
- if not first2 :
270
- data += ","
271
- first2 = False
272
- data += escape_char (d )
273
- data += "])"
274
- format_table_content (f , data , 8 )
275
- f .write ("\n ];\n \n " )
276
-
277
- f .write (" // Compatibility decompositions\n " )
278
- f .write (" static compatibility_table : &'static [(char, &'static [char])] = &[\n " )
279
- data = ""
280
- first = True
281
- for char in compat_keys :
282
- if not first :
283
- data += ","
284
- first = False
285
- data += "(%s,&[" % escape_char (char )
286
- first2 = True
287
- for d in compat [char ]:
288
- if not first2 :
289
- data += ","
290
- first2 = False
291
- data += escape_char (d )
292
- data += "])"
293
- format_table_content (f , data , 8 )
294
- f .write ("\n ];\n \n " )
295
-
296
- f .write (" static combining_class_table : &'static [(char, char, u8)] = &[\n " )
297
- ix = 0
298
- for pair in combine :
299
- f .write (ch_prefix (ix ))
300
- f .write ("(%s, %s, %s)" % (escape_char (pair [0 ]), escape_char (pair [1 ]), pair [2 ]))
301
- ix += 1
302
- f .write ("\n ];\n " )
303
-
304
- f .write (" pub fn canonical(c: char, i: &fn(char)) "
305
- + "{ d(c, i, false); }\n \n " )
306
- f .write (" pub fn compatibility(c: char, i: &fn(char)) "
307
- + "{ d(c, i, true); }\n \n " )
308
- f .write (" pub fn canonical_combining_class(c: char) -> u8 {\n "
309
- + " bsearch_range_value_table(c, combining_class_table)\n "
310
- + " }\n \n " )
311
- f .write (" fn d(c: char, i: &fn(char), k: bool) {\n " )
312
- f .write (" use iterator::Iterator;\n " );
203
+ f .write (" d(%s, i, k);\n "
204
+ % escape_char (d ))
205
+ f .write (" }\n " )
313
206
314
- f .write (" if c <= '\\ x7f' { i(c); return; }\n " )
315
-
316
- # First check the canonical decompositions
317
- f .write ("""
318
- match bsearch_table(c, canonical_table) {
319
- Some(canon) => {
320
- for x in canon.iter() {
321
- d(*x, |b| i(b), k);
322
- }
323
- return;
324
- }
325
- None => ()
326
- }\n \n """ )
207
+ f .write (" _ { }\n " )
208
+ f .write (" }\n \n " )
327
209
328
210
# Bottom out if we're not doing compat.
329
- f .write (" if !k { i(c); return ; }\n " )
211
+ f .write (" if !k { i(c); ret ; }\n \n " )
330
212
331
213
# Then check the compatibility decompositions
332
- f .write ("""
333
- match bsearch_table(c, compatibility_table) {
334
- Some(compat) => {
335
- for x in compat.iter() {
336
- d(*x, |b| i(b), k);
337
- }
338
- return;
339
- }
340
- None => ()
341
- }\n \n """ )
214
+ f .write (" // Compatibility decomposition\n " )
215
+ f .write (" alt c {\n " )
216
+ for char in compat_keys :
217
+ f .write (" %s {\n " % escape_char (char ))
218
+ for d in compat [char ]:
219
+ f .write (" d(%s, i, k);\n "
220
+ % escape_char (d ))
221
+ f .write (" }\n " )
222
+
223
+ f .write (" _ { }\n " )
224
+ f .write (" }\n \n " )
342
225
343
226
# Finally bottom out.
344
227
f .write (" i(c);\n " )
@@ -351,7 +234,7 @@ def emit_decomp_module(f, canon, compat, combine):
351
234
os .remove (i );
352
235
rf = open (r , "w" )
353
236
354
- (canon_decomp , compat_decomp , gencats , combines ) = load_unicode_data ("UnicodeData.txt" )
237
+ (canon_decomp , compat_decomp , gencats ) = load_unicode_data ("UnicodeData.txt" )
355
238
356
239
# Preamble
357
240
rf .write ('''// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
@@ -373,7 +256,7 @@ def emit_decomp_module(f, canon, compat, combine):
373
256
374
257
emit_property_module (rf , "general_category" , gencats )
375
258
376
- emit_decomp_module (rf , canon_decomp , compat_decomp , combines )
259
+ # emit_decomp_module(rf, canon_decomp, compat_decomp)
377
260
378
261
derived = load_derived_core_properties ("DerivedCoreProperties.txt" )
379
262
emit_property_module (rf , "derived_property" , derived )
0 commit comments