Make libcore/unicode/tables.rs compatible with rustfmt
This commit is contained in:
parent
f4cff27792
commit
28eb31f8dc
2 changed files with 36 additions and 29 deletions
|
@ -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'])
|
||||
];
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue