62
62
63
63
def fetch (f ):
64
64
if not os .path .exists (os .path .basename (f )):
65
- os .system ("curl -O http://www.unicode.org/Public/UNIDATA/%s"
66
- % f )
65
+ os .system ("curl -O http://www.unicode.org/Public/UNIDATA/{}" .format (f ))
67
66
68
67
if not os .path .exists (os .path .basename (f )):
69
- sys .stderr .write ("cannot load %s" % f )
68
+ sys .stderr .write ("cannot load {}" . format ( f ) )
70
69
exit (1 )
71
70
72
71
return open (f )
@@ -194,7 +193,7 @@ def group_cat(cat):
194
193
cur_end = cur_start
195
194
for letter in letters :
196
195
assert letter > cur_end , \
197
- "cur_end: %s , letter: %s" % ( hex ( cur_end ), hex ( letter ) )
196
+ "cur_end: {:#x} , letter: {:#x}" . format ( cur_end , letter )
198
197
if letter == cur_end + 1 :
199
198
cur_end = letter
200
199
else :
@@ -277,10 +276,10 @@ def load_properties(fname, interestingprops):
277
276
return props
278
277
279
278
def escape_char (c ):
280
- return "'\\ u{%x}'" % c if c != 0 else "'\\ 0'"
279
+ return "'\\ u{{{:x}}}'" . format ( c ) if c != 0 else "'\\ 0'"
281
280
282
281
def emit_table (f , name , t_data ):
283
- f .write (" const %s : &[(char, [char; 3])] = &[\n " % (name , ))
282
+ f .write (" const {} : &[(char, [char; 3])] = &[\n " . format (name ))
284
283
data = (
285
284
part
286
285
for dat in t_data
@@ -323,7 +322,7 @@ def emit_bool_trie(f, name, t_data):
323
322
chunk |= 1 << j
324
323
chunks .append (chunk )
325
324
326
- f .write (" pub const %s : &super::BoolTrie = &super::BoolTrie {\n " % (name , ))
325
+ f .write (" pub const {} : &super::BoolTrie = &super::BoolTrie {{ \n " . format (name ))
327
326
f .write (" r1: [\n " )
328
327
data = ('0x%016x' % chunk for chunk in chunks [0 :0x800 // CHUNK ])
329
328
format_table_content (f , data , 12 )
@@ -368,8 +367,7 @@ def emit_small_bool_trie(f, name, t_data):
368
367
print (cp , cp // 64 , len (chunks ), lo , hi )
369
368
chunks [cp // 64 ] |= 1 << (cp & 63 )
370
369
371
- f .write (" pub const %s: &super::SmallBoolTrie = &super::SmallBoolTrie {\n "
372
- % (name ,))
370
+ f .write (" pub const {}: &super::SmallBoolTrie = &super::SmallBoolTrie {{\n " .format (name ))
373
371
374
372
(r1 , r2 ) = compute_trie (chunks , 1 )
375
373
@@ -386,17 +384,17 @@ def emit_small_bool_trie(f, name, t_data):
386
384
f .write (" };\n \n " )
387
385
388
386
def emit_property_module (f , mod , tbl , emit ):
389
- f .write ("pub mod %s { \n " % mod )
387
+ f .write ("pub mod {} {{ \n " . format ( mod ) )
390
388
for cat in sorted (emit ):
391
389
if cat in ["Cc" , "White_Space" , "Pattern_White_Space" ]:
392
- emit_small_bool_trie (f , "%s_table" % cat , tbl [cat ])
393
- f .write (" pub fn %s (c: char) -> bool {\n " % cat )
394
- f .write (" %s_table .lookup(c)\n " % cat )
390
+ emit_small_bool_trie (f , "{}_table" . format ( cat ) , tbl [cat ])
391
+ f .write (" pub fn {} (c: char) -> bool {{ \n " . format ( cat ) )
392
+ f .write (" {}_table .lookup(c)\n " . format ( cat ) )
395
393
f .write (" }\n \n " )
396
394
else :
397
- emit_bool_trie (f , "%s_table" % cat , tbl [cat ])
398
- f .write (" pub fn %s (c: char) -> bool {\n " % cat )
399
- f .write (" %s_table .lookup(c)\n " % cat )
395
+ emit_bool_trie (f , "{}_table" . format ( cat ) , tbl [cat ])
396
+ f .write (" pub fn {} (c: char) -> bool {{ \n " . format ( cat ) )
397
+ f .write (" {}_table .lookup(c)\n " . format ( cat ) )
400
398
f .write (" }\n \n " )
401
399
f .write ("}\n \n " )
402
400
@@ -461,13 +459,13 @@ def emit_norm_module(f, canon, compat, combine, norm_props):
461
459
/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of
462
460
/// `char` and `str` methods are based on.
463
461
#[unstable(feature = "unicode_version", issue = "49726")]
464
- pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {
465
- major: %s ,
466
- minor: %s ,
467
- micro: %s ,
462
+ pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {{
463
+ major: {} ,
464
+ minor: {} ,
465
+ micro: {} ,
468
466
_priv: (),
469
- };
470
- """ % unicode_version )
467
+ }} ;
468
+ """ . format ( * unicode_version ) )
471
469
(canon_decomp , compat_decomp , gencats , combines ,
472
470
to_upper , to_lower , to_title ) = load_unicode_data ()
473
471
load_special_casing (to_upper , to_lower , to_title )
0 commit comments