-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
28 lines (24 loc) · 921 Bytes
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::{
env,
fs::{self, File},
io::Write,
};
fn main() {
let string = fs::read_to_string("res/UnicodeData.txt").expect("Failed to load unicode data!");
let mut file = File::create(format!("{}/unicode.rs", env::var("OUT_DIR").unwrap()))
.expect("Unable to create unicode output file!");
file.write_all(b"#[allow(text_direction_codepoint_in_literal)]\nconst UNICODE_CHARS: &[(&str, &str)] = &[\n")
.unwrap();
string.lines().for_each(|line| {
let fields = line.split(';').collect::<Vec<_>>();
let chr = match char::from_u32(u32::from_str_radix(fields[0], 16).unwrap()) {
Some(char) => char,
None => return,
};
if fields[1] != "<control>" {
file.write_all(format!("(r#\"{}\"#, r#\"{}\"#),\n", fields[1], chr).as_bytes())
.unwrap();
}
});
file.write_all(b"];\n").unwrap();
}