-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.rs
34 lines (29 loc) · 965 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
29
30
31
32
33
34
extern crate phf_codegen;
#[path = "./src/unicode_name_list.rs"]
mod unicode_name_list;
use std::env;
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::Path;
fn main() {
for (name, value) in env::vars() {
println!("{} = {}", name, value);
}
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("unicode_name_map_gen.rs");
let mut file = BufWriter::new(File::create(&path).unwrap());
write!(
&mut file,
"#[allow(clippy::unreadable_literal)]\nstatic UNICODE_NAME_MAP: phf::Map<&'static str, char> =\n"
)
.unwrap();
let mut map = phf_codegen::Map::new();
for (name, c) in unicode_name_list::UNICODE_NAME_LIST {
match *c {
'\'' => map.entry(*name, "'\\''"),
'\\' => map.entry(*name, "'\\\\'"),
_ => map.entry(*name, format!("'{}'", c).as_str()),
};
}
map.build(&mut file).unwrap();
write!(&mut file, ";\n").unwrap();
}