Skip to content

Commit f1effaf

Browse files
committed
Set up data.rs
1 parent 60f97b0 commit f1effaf

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

build.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
use std::collections::HashMap;
1+
use std::collections::BTreeMap;
2+
use std::fs::File;
3+
use std::io::Write;
4+
use std::path::Path;
25

36
const DATA: &str = include_str!("vendor/detect-writing-script/data.json");
47

8+
macro_rules! ok(
9+
($result:expr) => ($result.unwrap());
10+
);
11+
512
fn main() {
6-
let _: HashMap<String, Vec<[usize; 2]>> = serde_json::from_str(DATA).unwrap();
13+
let data: BTreeMap<String, Vec<[u32; 2]>> = ok!(serde_json::from_str(DATA));
14+
let script_count = data.len();
15+
16+
let root = ok!(std::env::var("OUT_DIR"));
17+
let path = Path::new(&root).join("data.rs");
18+
let mut file = ok!(File::create(&path));
19+
ok!(write!(
20+
file,
21+
r#"
22+
const SCRIPT_COUNT: usize = {script_count};
23+
"#,
24+
));
725
}

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
11
//! Detection of writing scripts from Unicode codepoints.
2+
3+
include!(concat!(env!("OUT_DIR"), "/data.rs"));
4+
5+
/// A match.
6+
#[derive(Clone, Copy)]
7+
pub struct Match {
8+
pub name: &'static str,
9+
pub count: usize,
10+
pub score: f64,
11+
}
12+
13+
/// Detect writing scripts given ranges of Unicode codepoints.
14+
pub fn detect<T>(_codepoints: T, _threshold: f64) -> Vec<Match>
15+
where
16+
T: IntoIterator<Item = [u32; 2]>,
17+
{
18+
let _ = [0; SCRIPT_COUNT];
19+
20+
unimplemented!()
21+
}

0 commit comments

Comments
 (0)