Skip to content

Commit 3683b08

Browse files
author
Thom Chiovoloni
committed
Generate case_folding_table.rs in advance
1 parent 7cb56f9 commit 3683b08

File tree

5 files changed

+1431
-26
lines changed

5 files changed

+1431
-26
lines changed

Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ description = "Unicode caseless matching"
66
repository = "https://github.com/SimonSapin/rust-caseless"
77
license = "MIT"
88

9-
build = "src/build.rs"
10-
11-
[build-dependencies]
12-
regex = "1.0"
13-
149
[dependencies]
1510
unicode-normalization = "0.1"
11+
12+
[workspace]
13+
members = [
14+
".",
15+
"print-table",
16+
]

print-table/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "print-table"
3+
version = "0.2.1"
4+
authors = ["Simon Sapin <[email protected]>"]
5+
license = "MIT"
6+
publish = false
7+
8+
[dependencies]
9+
regex = "1"
10+

src/build.rs renamed to print-table/src/main.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
extern crate regex;
22

33
use std::char;
4-
use std::env;
5-
use std::fs::File;
6-
use std::io::Write;
7-
use std::path::Path;
84
use regex::Regex;
95

106
// Case folding a single code point can give up to this many code points.
117
const MAX_FOLDED_CODE_POINTS: usize = 3;
128

139
fn main() {
14-
let mut lines = include_str!("../CaseFolding.txt").lines();
10+
let mut lines = include_str!("../../CaseFolding.txt").lines();
1511
let first_line = lines.next().unwrap();
1612
let version_regex = Regex::new(r"^# CaseFolding-(\d+)\.(\d+)\.(\d+).txt$").unwrap();
1713
let unicode_version = &version_regex.captures(first_line).unwrap();
@@ -21,15 +17,8 @@ fn main() {
2117
unicode_version[3].parse().unwrap(),
2218
);
2319

24-
let dst = Path::new(&env::var("OUT_DIR").unwrap()).join("case_folding_data.rs");
25-
let f = &mut File::create(&dst).unwrap();
26-
27-
macro_rules! w {
28-
($($args: tt)+) => { (write!(f, $($args)+)).unwrap(); }
29-
};
30-
31-
w!("pub const UNICODE_VERSION: (u64, u64, u64) = ({}, {}, {});\n", major, minor, patch);
32-
w!("const CASE_FOLDING_TABLE: &'static [(char, [char; 3])] = &[\n");
20+
print!("pub const UNICODE_VERSION: (u64, u64, u64) = ({}, {}, {});\n", major, minor, patch);
21+
print!("pub const CASE_FOLDING_TABLE: &'static [(char, [char; 3])] = &[\n");
3322

3423
// Entry with C (common case folding) or F (full case folding) status
3524
let c_or_f_entry = Regex::new(r"^([0-9A-F]+); [CF]; ([0-9A-F ]+);").unwrap();
@@ -42,17 +31,17 @@ fn main() {
4231
let blanks = MAX_FOLDED_CODE_POINTS - to.len();
4332
let mut to = to.into_iter();
4433
let first_to = to.next().unwrap();
45-
w!(" ('{}', ['{}'", hex_to_escaped(from), first_to);
34+
print!(" ('{}', ['{}'", hex_to_escaped(from), first_to);
4635
for c in to {
47-
w!(", '{}'", c);
36+
print!(", '{}'", c);
4837
}
4938
for _ in 0..blanks {
50-
w!(", '\\0'");
39+
print!(", '\\0'");
5140
}
52-
w!("]),\n");
41+
print!("]),\n");
5342
}
5443
}
55-
w!("];\n");
44+
print!("];\n");
5645
}
5746

5847

0 commit comments

Comments
 (0)