-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
36 lines (32 loc) · 1000 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
35
36
extern crate phf_codegen;
use std::convert::{TryFrom, TryInto};
use std::env;
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::Path;
fn main() {
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs");
let mut file = BufWriter::new(File::create(&path).unwrap());
let mut map = phf_codegen::Map::new();
let lines = include_str!("table");
for line in lines.split_ascii_whitespace() {
let key: char = u32::from_str_radix(&line[..4], 16)
.unwrap()
.try_into()
.unwrap();
let mut value = line[5..]
.split('&')
.map(|s| u32::from_str_radix(s, 16).unwrap())
.map(|u| char::try_from(u).unwrap())
.collect::<String>();
value.insert(0, '"');
value.push('"');
map.entry(key, &value);
}
writeln!(
&mut file,
"static TABLE: phf::Map<char, &'static str> = \n{};\n",
map.build()
)
.unwrap();
}