diff options
Diffstat (limited to 'src/libcore/unicode')
| -rwxr-xr-x[-rw-r--r--] | src/libcore/unicode/printable.py | 6 | ||||
| -rw-r--r-- | src/libcore/unicode/printable.rs | 9 | ||||
| -rw-r--r-- | src/libcore/unicode/tables.rs | 29 | ||||
| -rwxr-xr-x | src/libcore/unicode/unicode.py | 36 |
4 files changed, 47 insertions, 33 deletions
diff --git a/src/libcore/unicode/printable.py b/src/libcore/unicode/printable.py index 4e8b4ecad02..91db6381c9b 100644..100755 --- a/src/libcore/unicode/printable.py +++ b/src/libcore/unicode/printable.py @@ -111,16 +111,19 @@ def compress_normal(normal): return compressed def print_singletons(uppers, lowers, uppersname, lowersname): + print("#[rustfmt::skip]") print("const {}: &[(u8, u8)] = &[".format(uppersname)) for u, c in uppers: print(" ({:#04x}, {}),".format(u, c)) print("];") + print("#[rustfmt::skip]") print("const {}: &[u8] = &[".format(lowersname)) for i in range(0, len(lowers), 8): print(" {}".format(" ".join("{:#04x},".format(l) for l in lowers[i:i+8]))) print("];") def print_normal(normal, normalname): + print("#[rustfmt::skip]") print("const {}: &[u8] = &[".format(normalname)) for v in normal: print(" {}".format(" ".join("{:#04x},".format(i) for i in v))) @@ -170,8 +173,7 @@ def main(): // NOTE: The following code was generated by "src/libcore/unicode/printable.py", // do not edit directly! -fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8], - normal: &[u8]) -> bool { +fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8], normal: &[u8]) -> bool { let xupper = (x >> 8) as u8; let mut lowerstart = 0; for &(upper, lowercount) in singletonuppers { diff --git a/src/libcore/unicode/printable.rs b/src/libcore/unicode/printable.rs index d411dda7dc1..eee9ea52ef0 100644 --- a/src/libcore/unicode/printable.rs +++ b/src/libcore/unicode/printable.rs @@ -1,8 +1,7 @@ // NOTE: The following code was generated by "src/libcore/unicode/printable.py", // do not edit directly! -fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8], - normal: &[u8]) -> bool { +fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8], normal: &[u8]) -> bool { let xupper = (x >> 8) as u8; let mut lowerstart = 0; for &(upper, lowercount) in singletonuppers { @@ -70,6 +69,7 @@ pub(crate) fn is_printable(x: char) -> bool { } } +#[rustfmt::skip] const SINGLETONS0U: &[(u8, u8)] = &[ (0x00, 1), (0x03, 5), @@ -113,6 +113,7 @@ const SINGLETONS0U: &[(u8, u8)] = &[ (0xfe, 3), (0xff, 9), ]; +#[rustfmt::skip] const SINGLETONS0L: &[u8] = &[ 0xad, 0x78, 0x79, 0x8b, 0x8d, 0xa2, 0x30, 0x57, 0x58, 0x8b, 0x8c, 0x90, 0x1c, 0x1d, 0xdd, 0x0e, @@ -152,6 +153,7 @@ const SINGLETONS0L: &[u8] = &[ 0xff, 0x53, 0x67, 0x75, 0xc8, 0xc9, 0xd0, 0xd1, 0xd8, 0xd9, 0xe7, 0xfe, 0xff, ]; +#[rustfmt::skip] const SINGLETONS1U: &[(u8, u8)] = &[ (0x00, 6), (0x01, 1), @@ -189,6 +191,7 @@ const SINGLETONS1U: &[(u8, u8)] = &[ (0xf9, 6), (0xfa, 2), ]; +#[rustfmt::skip] const SINGLETONS1L: &[u8] = &[ 0x0c, 0x27, 0x3b, 0x3e, 0x4e, 0x4f, 0x8f, 0x9e, 0x9e, 0x9f, 0x06, 0x07, 0x09, 0x36, 0x3d, 0x3e, @@ -212,6 +215,7 @@ const SINGLETONS1L: &[u8] = &[ 0xa4, 0xaa, 0xaf, 0xb0, 0xc0, 0xd0, 0x0c, 0x72, 0xa3, 0xa4, 0xcb, 0xcc, 0x6e, 0x6f, ]; +#[rustfmt::skip] const NORMAL0: &[u8] = &[ 0x00, 0x20, 0x5f, 0x22, @@ -355,6 +359,7 @@ const NORMAL0: &[u8] = &[ 0x1b, 0x03, 0x0f, 0x0d, ]; +#[rustfmt::skip] const NORMAL1: &[u8] = &[ 0x5e, 0x22, 0x7b, 0x05, diff --git a/src/libcore/unicode/tables.rs b/src/libcore/unicode/tables.rs index 5b5be485431..3fa125e8fea 100644 --- a/src/libcore/unicode/tables.rs +++ b/src/libcore/unicode/tables.rs @@ -2,19 +2,16 @@ #![allow(missing_docs, non_upper_case_globals, non_snake_case, clippy::unreadable_literal)] -use crate::unicode::version::UnicodeVersion; use crate::unicode::bool_trie::{BoolTrie, SmallBoolTrie}; +use crate::unicode::version::UnicodeVersion; /// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of /// `char` and `str` methods are based on. #[unstable(feature = "unicode_version", issue = "49726")] -pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion { - major: 12, - minor: 1, - micro: 0, - _priv: (), -}; +pub const UNICODE_VERSION: UnicodeVersion = + UnicodeVersion { major: 12, minor: 1, micro: 0, _priv: () }; pub(crate) mod general_category { + #[rustfmt::skip] const Cc_table: &super::SmallBoolTrie = &super::SmallBoolTrie { r1: &[ 0, 1, 0 @@ -28,6 +25,7 @@ pub(crate) mod general_category { Cc_table.lookup(c) } + #[rustfmt::skip] const N_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x03ff000000000000, 0x0000000000000000, 0x720c000000000000, 0x0000000000000000, @@ -138,10 +136,10 @@ pub(crate) mod general_category { pub fn N(c: char) -> bool { N_table.lookup(c) } - } pub(crate) mod derived_property { + #[rustfmt::skip] const Alphabetic_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x0000000000000000, 0x07fffffe07fffffe, 0x0420040000000000, 0xff7fffffff7fffff, @@ -327,6 +325,7 @@ pub(crate) mod derived_property { Alphabetic_table.lookup(c) } + #[rustfmt::skip] const Case_Ignorable_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x0400408000000000, 0x0000000140000000, 0x0190a10000000000, 0x0000000000000000, @@ -464,6 +463,7 @@ pub(crate) mod derived_property { Case_Ignorable_table.lookup(c) } + #[rustfmt::skip] const Cased_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x0000000000000000, 0x07fffffe07fffffe, 0x0420040000000000, 0xff7fffffff7fffff, @@ -565,6 +565,7 @@ pub(crate) mod derived_property { Cased_table.lookup(c) } + #[rustfmt::skip] const Grapheme_Extend_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, @@ -689,6 +690,7 @@ pub(crate) mod derived_property { Grapheme_Extend_table.lookup(c) } + #[rustfmt::skip] const Lowercase_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x0000000000000000, 0x07fffffe00000000, 0x0420040000000000, 0xff7fffff80000000, @@ -789,6 +791,7 @@ pub(crate) mod derived_property { Lowercase_table.lookup(c) } + #[rustfmt::skip] const Uppercase_table: &super::BoolTrie = &super::BoolTrie { r1: [ 0x0000000000000000, 0x0000000007fffffe, 0x0000000000000000, 0x000000007f7fffff, @@ -889,10 +892,10 @@ pub(crate) mod derived_property { pub fn Uppercase(c: char) -> bool { Uppercase_table.lookup(c) } - } pub(crate) mod property { + #[rustfmt::skip] const White_Space_table: &super::SmallBoolTrie = &super::SmallBoolTrie { r1: &[ 0, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -912,20 +915,19 @@ pub(crate) mod property { pub fn White_Space(c: char) -> bool { White_Space_table.lookup(c) } - } pub(crate) mod conversions { pub fn to_lower(c: char) -> [char; 3] { match bsearch_case_table(c, to_lowercase_table) { - None => [c, '\0', '\0'], + None => [c, '\0', '\0'], Some(index) => to_lowercase_table[index].1, } } pub fn to_upper(c: char) -> [char; 3] { match bsearch_case_table(c, to_uppercase_table) { - None => [c, '\0', '\0'], + None => [c, '\0', '\0'], Some(index) => to_uppercase_table[index].1, } } @@ -934,6 +936,7 @@ pub(crate) mod conversions { table.binary_search_by(|&(key, _)| key.cmp(&c)).ok() } + #[rustfmt::skip] const to_lowercase_table: &[(char, [char; 3])] = &[ ('\u{41}', ['\u{61}', '\0', '\0']), ('\u{42}', ['\u{62}', '\0', '\0']), ('\u{43}', ['\u{63}', '\0', '\0']), ('\u{44}', ['\u{64}', '\0', '\0']), ('\u{45}', ['\u{65}', '\0', @@ -1558,6 +1561,7 @@ pub(crate) mod conversions { ('\u{1e920}', ['\u{1e942}', '\0', '\0']), ('\u{1e921}', ['\u{1e943}', '\0', '\0']) ]; + #[rustfmt::skip] const to_uppercase_table: &[(char, [char; 3])] = &[ ('\u{61}', ['\u{41}', '\0', '\0']), ('\u{62}', ['\u{42}', '\0', '\0']), ('\u{63}', ['\u{43}', '\0', '\0']), ('\u{64}', ['\u{44}', '\0', '\0']), ('\u{65}', ['\u{45}', '\0', @@ -2228,5 +2232,4 @@ pub(crate) mod conversions { ('\u{1e940}', ['\u{1e91e}', '\0', '\0']), ('\u{1e941}', ['\u{1e91f}', '\0', '\0']), ('\u{1e942}', ['\u{1e920}', '\0', '\0']), ('\u{1e943}', ['\u{1e921}', '\0', '\0']) ]; - } diff --git a/src/libcore/unicode/unicode.py b/src/libcore/unicode/unicode.py index 89894f7932d..97df92a56da 100755 --- a/src/libcore/unicode/unicode.py +++ b/src/libcore/unicode/unicode.py @@ -81,8 +81,8 @@ PREAMBLE = """\ #![allow(missing_docs, non_upper_case_globals, non_snake_case, clippy::unreadable_literal)] -use crate::unicode::version::UnicodeVersion; use crate::unicode::bool_trie::{{BoolTrie, SmallBoolTrie}}; +use crate::unicode::version::UnicodeVersion; """.format(year=datetime.datetime.now().year) # Mapping taken from Table 12 from: @@ -555,6 +555,8 @@ def generate_table( if is_pub: pub_string = "pub " + yield "\n" + yield " #[rustfmt::skip]\n" yield " %sconst %s: %s = &[\n" % (pub_string, name, decl_type) data = [] @@ -568,7 +570,7 @@ def generate_table( for table_line in generate_table_lines("".join(data).split(","), 8): yield table_line - yield "\n ];\n\n" + yield "\n ];\n" def compute_trie(raw_data, chunk_size): @@ -634,6 +636,9 @@ def generate_bool_trie(name, codepoint_ranges, is_pub=False): pub_string = "" if is_pub: pub_string = "pub " + + yield "\n" + yield " #[rustfmt::skip]\n" yield " %sconst %s: &super::BoolTrie = &super::BoolTrie {\n" % (pub_string, name) yield " r1: [\n" data = ("0x%016x" % chunk for chunk in chunks[:0x800 // chunk_size]) @@ -678,7 +683,7 @@ def generate_bool_trie(name, codepoint_ranges, is_pub=False): yield fragment yield "\n ],\n" - yield " };\n\n" + yield " };\n" def generate_small_bool_trie(name, codepoint_ranges, is_pub=False): @@ -700,6 +705,8 @@ def generate_small_bool_trie(name, codepoint_ranges, is_pub=False): if is_pub: pub_string = "pub " + yield "\n" + yield " #[rustfmt::skip]\n" yield (" %sconst %s: &super::SmallBoolTrie = &super::SmallBoolTrie {\n" % (pub_string, name)) @@ -717,7 +724,7 @@ def generate_small_bool_trie(name, codepoint_ranges, is_pub=False): yield fragment yield "\n ],\n" - yield " };\n\n" + yield " };\n" def generate_property_module(mod, grouped_categories, category_subset): @@ -726,7 +733,7 @@ def generate_property_module(mod, grouped_categories, category_subset): Generate Rust code for module defining properties. """ - yield "pub(crate) mod %s {\n" % mod + yield "pub(crate) mod %s {" % mod for cat in sorted(category_subset): if cat in ("Cc", "White_Space"): generator = generate_small_bool_trie("%s_table" % cat, grouped_categories[cat]) @@ -736,9 +743,10 @@ def generate_property_module(mod, grouped_categories, category_subset): for fragment in generator: yield fragment + yield "\n" yield " pub fn %s(c: char) -> bool {\n" % cat yield " %s_table.lookup(c)\n" % cat - yield " }\n\n" + yield " }\n" yield "}\n\n" @@ -753,21 +761,21 @@ def generate_conversions_module(unicode_data): yield """ pub fn to_lower(c: char) -> [char; 3] { match bsearch_case_table(c, to_lowercase_table) { - None => [c, '\\0', '\\0'], + None => [c, '\\0', '\\0'], Some(index) => to_lowercase_table[index].1, } } pub fn to_upper(c: char) -> [char; 3] { match bsearch_case_table(c, to_uppercase_table) { - None => [c, '\\0', '\\0'], + None => [c, '\\0', '\\0'], Some(index) => to_uppercase_table[index].1, } } fn bsearch_case_table(c: char, table: &[(char, [char; 3])]) -> Option<usize> { table.binary_search_by(|&(key, _)| key.cmp(&c)).ok() - }\n\n""" + }\n""" decl_type = "&[(char, [char; 3])]" format_conversion = lambda x: "({},[{},{},{}])".format(*( @@ -827,13 +835,9 @@ def main(): /// The version of [Unicode](http://www.unicode.org/) that the Unicode parts of /// `char` and `str` methods are based on. #[unstable(feature = "unicode_version", issue = "49726")] - pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {{ - major: {version.major}, - minor: {version.minor}, - micro: {version.micro}, - _priv: (), - }}; - """).format(version=unicode_version) + pub const UNICODE_VERSION: UnicodeVersion = + UnicodeVersion {{ major: {v.major}, minor: {v.minor}, micro: {v.micro}, _priv: () }}; + """).format(v=unicode_version) buf.write(unicode_version_notice) get_path = lambda f: get_unicode_file_path(unicode_version, f) |
