Skip to content

Commit 5b6c88b

Browse files
author
Clar Charr
committed
Use format instead of % in unicode.py
1 parent 6fcf1b4 commit 5b6c88b

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/libcore/unicode/unicode.py

+20-22
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@
6262

6363
def fetch(f):
6464
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))
6766

6867
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))
7069
exit(1)
7170

7271
return open(f)
@@ -194,7 +193,7 @@ def group_cat(cat):
194193
cur_end = cur_start
195194
for letter in letters:
196195
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)
198197
if letter == cur_end + 1:
199198
cur_end = letter
200199
else:
@@ -277,10 +276,10 @@ def load_properties(fname, interestingprops):
277276
return props
278277

279278
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'"
281280

282281
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))
284283
data = (
285284
part
286285
for dat in t_data
@@ -323,7 +322,7 @@ def emit_bool_trie(f, name, t_data):
323322
chunk |= 1 << j
324323
chunks.append(chunk)
325324

326-
f.write(" pub const %s: &super::BoolTrie = &super::BoolTrie {\n" % (name,))
325+
f.write(" pub const {}: &super::BoolTrie = &super::BoolTrie {{\n".format(name))
327326
f.write(" r1: [\n")
328327
data = ('0x%016x' % chunk for chunk in chunks[0:0x800 // CHUNK])
329328
format_table_content(f, data, 12)
@@ -368,8 +367,7 @@ def emit_small_bool_trie(f, name, t_data):
368367
print(cp, cp // 64, len(chunks), lo, hi)
369368
chunks[cp // 64] |= 1 << (cp & 63)
370369

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))
373371

374372
(r1, r2) = compute_trie(chunks, 1)
375373

@@ -386,17 +384,17 @@ def emit_small_bool_trie(f, name, t_data):
386384
f.write(" };\n\n")
387385

388386
def emit_property_module(f, mod, tbl, emit):
389-
f.write("pub mod %s {\n" % mod)
387+
f.write("pub mod {} {{\n".format(mod))
390388
for cat in sorted(emit):
391389
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))
395393
f.write(" }\n\n")
396394
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))
400398
f.write(" }\n\n")
401399
f.write("}\n\n")
402400

@@ -461,13 +459,13 @@ def emit_norm_module(f, canon, compat, combine, norm_props):
461459
/// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of
462460
/// `char` and `str` methods are based on.
463461
#[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: {},
468466
_priv: (),
469-
};
470-
""" % unicode_version)
467+
}};
468+
""".format(*unicode_version))
471469
(canon_decomp, compat_decomp, gencats, combines,
472470
to_upper, to_lower, to_title) = load_unicode_data()
473471
load_special_casing(to_upper, to_lower, to_title)

0 commit comments

Comments
 (0)