-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
35 lines (27 loc) · 1.01 KB
/
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::env;
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::Path;
use std::io::{BufRead, BufReader};
fn main() {
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs");
let mut file = BufWriter::new(File::create(&path).unwrap());
let uni_data = File::open("UnicodeDataFixed.txt").unwrap();
let mut builder = phf_codegen::Map::new();
for line in BufReader::new(uni_data).lines() {
let l = line.unwrap();
let mut data = l.split(';');
let num = u32::from_str_radix(data.next().unwrap(), 16).unwrap();
let name = data.next().unwrap();
builder.entry(num, &format!("\"{}\"", name));
}
writeln!(
&mut file,
"static UNICODE: ::phf::Map<u32, &'static str> = \n{};",
builder.build(),
)
.unwrap();
}