about summary refs log tree commit diff
path: root/src/tools/unicode-table-generator
diff options
context:
space:
mode:
authorMartin Gammelsæter <martin@mg.am>2023-03-15 17:23:48 +0100
committerMartin Gammelsæter <martin@mg.am>2023-03-15 17:27:23 +0100
commit8a4eb9e3a87b1fb9a5078f6f45cf62e2f9f8bc2b (patch)
tree902a80b786e1a68027ff10d9a6f4e1d1e9d75eb5 /src/tools/unicode-table-generator
parent992d154f3a84cc8abcefcf6e6cf3698e4821b506 (diff)
downloadrust-8a4eb9e3a87b1fb9a5078f6f45cf62e2f9f8bc2b.tar.gz
rust-8a4eb9e3a87b1fb9a5078f6f45cf62e2f9f8bc2b.zip
Skip serializing ascii chars in case LUTs
Since ascii chars are already handled by a special case in the
`to_lower` and `to_upper` functions, there's no need to waste space on
them in the LUTs.
Diffstat (limited to 'src/tools/unicode-table-generator')
-rw-r--r--src/tools/unicode-table-generator/src/case_mapping.rs25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/tools/unicode-table-generator/src/case_mapping.rs b/src/tools/unicode-table-generator/src/case_mapping.rs
index 992aac1f857..b8153a71118 100644
--- a/src/tools/unicode-table-generator/src/case_mapping.rs
+++ b/src/tools/unicode-table-generator/src/case_mapping.rs
@@ -1,27 +1,24 @@
 use crate::{fmt_list, UnicodeData};
-use std::fmt;
+use std::{collections::BTreeMap, fmt};
 
 pub(crate) fn generate_case_mapping(data: &UnicodeData) -> String {
     let mut file = String::new();
 
     file.push_str(HEADER.trim_start());
-
-    let decl_type = "&[(char, [char; 3])]";
-
-    file.push_str(&format!(
-        "static LOWERCASE_TABLE: {} = &[{}];",
-        decl_type,
-        fmt_list(data.to_lower.iter().map(to_mapping))
-    ));
+    file.push_str(&generate_table("LOWER", &data.to_lower));
     file.push_str("\n\n");
-    file.push_str(&format!(
-        "static UPPERCASE_TABLE: {} = &[{}];",
-        decl_type,
-        fmt_list(data.to_upper.iter().map(to_mapping))
-    ));
+    file.push_str(&generate_table("UPPER", &data.to_upper));
     file
 }
 
+fn generate_table(case: &str, data: &BTreeMap<u32, (u32, u32, u32)>) -> String {
+    format!(
+        "static {}CASE_TABLE: &[(char, [char; 3])] = &[{}];",
+        case,
+        fmt_list(data.iter().map(to_mapping).filter(|(k, _)| !k.0.is_ascii()))
+    )
+}
+
 fn to_mapping((key, (a, b, c)): (&u32, &(u32, u32, u32))) -> (CharEscape, [CharEscape; 3]) {
     (
         CharEscape(std::char::from_u32(*key).unwrap()),