diff --git a/chrono-tz-build/Cargo.toml b/chrono-tz-build/Cargo.toml index 7a6c9c5..4cf3188 100644 --- a/chrono-tz-build/Cargo.toml +++ b/chrono-tz-build/Cargo.toml @@ -17,7 +17,7 @@ case-insensitive = ["uncased", "phf/uncased"] regex = ["dep:regex"] [dependencies] -parse-zoneinfo = { version = "0.3" } +parse-zoneinfo = { version = "0.3", path = "../parse-zoneinfo" } regex = { default-features = false, version = "1", optional = true } phf = { version = "0.11", default-features = false } phf_codegen = { version = "0.11", default-features = false } diff --git a/chrono-tz-build/src/lib.rs b/chrono-tz-build/src/lib.rs index 274e52c..9278142 100644 --- a/chrono-tz-build/src/lib.rs +++ b/chrono-tz-build/src/lib.rs @@ -509,26 +509,14 @@ fn detect_iana_db_version() -> String { pub fn main() { println!("cargo:rerun-if-env-changed={}", FILTER_ENV_VAR_NAME); - let parser = LineParser::new(); + let parser = LineParser::default(); let mut table = TableBuilder::new(); - - let tzfiles = [ - "tz/africa", - "tz/antarctica", - "tz/asia", - "tz/australasia", - "tz/backward", - "tz/etcetera", - "tz/europe", - "tz/northamerica", - "tz/southamerica", - ]; - - let lines = tzfiles + let lines = parse_zoneinfo::FILES .iter() - .map(Path::new) .map(|p| { - Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| String::new())).join(p) + Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| String::new())) + .join("tz") + .join(p) }) .map(|path| { File::open(&path).unwrap_or_else(|e| panic!("cannot open {}: {}", path.display(), e)) diff --git a/parse-zoneinfo/Cargo.toml b/parse-zoneinfo/Cargo.toml index b507199..7323a17 100644 --- a/parse-zoneinfo/Cargo.toml +++ b/parse-zoneinfo/Cargo.toml @@ -9,7 +9,5 @@ readme = "README.md" license = "MIT" keywords = ["date", "time", "timezone", "zone", "calendar"] -[dependencies.regex] -version = "1.3.1" -default-features = false -features = ["std", "unicode-perl"] +[dev-dependencies] +insta = "1.38" diff --git a/parse-zoneinfo/src/lib.rs b/parse-zoneinfo/src/lib.rs index bfcfd7f..2cdd048 100644 --- a/parse-zoneinfo/src/lib.rs +++ b/parse-zoneinfo/src/lib.rs @@ -38,3 +38,15 @@ pub mod line; pub mod structure; pub mod table; pub mod transitions; + +pub const FILES: &[&str] = &[ + "africa", + "antarctica", + "asia", + "australasia", + "backward", + "etcetera", + "europe", + "northamerica", + "southamerica", +]; diff --git a/parse-zoneinfo/src/line.rs b/parse-zoneinfo/src/line.rs index 19bc5a1..06fd6d6 100644 --- a/parse-zoneinfo/src/line.rs +++ b/parse-zoneinfo/src/line.rs @@ -71,18 +71,8 @@ use std::fmt; use std::str::FromStr; -use regex::{Captures, Regex}; - -pub struct LineParser { - rule_line: Regex, - day_field: Regex, - hm_field: Regex, - hms_field: Regex, - zone_line: Regex, - continuation_line: Regex, - link_line: Regex, - empty_line: Regex, -} +#[derive(Clone, Copy)] +pub struct LineParser {} #[derive(PartialEq, Debug, Clone)] pub enum Error { @@ -133,100 +123,7 @@ impl std::error::Error for Error {} impl Default for LineParser { fn default() -> Self { - LineParser { - rule_line: Regex::new( - r##"(?x) ^ - Rule \s+ - ( ?P \S+) \s+ - ( ?P \S+) \s+ - ( ?P \S+) \s+ - ( ?P \S+) \s+ - ( ?P \S+) \s+ - ( ?P \S+) \s+ - ( ?P \S+) \s+ - ( ?P \S+) \s+ - ( ?P \S+) \s* - (\#.*)? - $ "##, - ) - .unwrap(), - - day_field: Regex::new( - r##"(?x) ^ - ( ?P \w+ ) - ( ?P [<>] = ) - ( ?P \d+ ) - $ "##, - ) - .unwrap(), - - hm_field: Regex::new( - r##"(?x) ^ - ( ?P -? ) - ( ?P \d{1,2} ) : ( ?P \d{2} ) - ( ?P [wsugz] )? - $ "##, - ) - .unwrap(), - - hms_field: Regex::new( - r##"(?x) ^ - ( ?P -? ) - ( ?P \d{1,2} ) : ( ?P \d{2} ) : ( ?P \d{2} ) - ( ?P [wsugz] )? - $ "##, - ) - .unwrap(), - - zone_line: Regex::new( - r##"(?x) ^ - Zone \s+ - ( ?P [A-Za-z0-9/_+-]+ ) \s+ - ( ?P \S+ ) \s+ - ( ?P \S+ ) \s+ - ( ?P \S+ ) \s* - ( ?P [0-9]+)? \s* - ( ?P [A-Za-z]+)? \s* - ( ?P [A-Za-z0-9><=]+ )? \s* - ( ?P