From 26608e4edcfafde18ed6c4e876036ff1fb56a50f Mon Sep 17 00:00:00 2001 From: Ben S Date: Sat, 26 Sep 2015 11:14:54 +0100 Subject: [PATCH 001/113] Initial commit --- .gitignore | 2 + Cargo.toml | 9 + src/lib.rs | 588 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 599 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a9d37c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..45cf7b2 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "olson-parse" +version = "0.1.0" +authors = ["Ben S "] + +[dependencies] +datetime = "*" +lazy_static = "*" +regex = "*" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..49e9fed --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,588 @@ +//! Parsing Olson DB formats. + +#![warn(missing_copy_implementations)] +#![warn(missing_debug_implementations)] +#![warn(missing_docs)] + +#![warn(trivial_casts, trivial_numeric_casts)] +#![warn(unused_qualifications)] +#![warn(unused_results)] + +use std::ascii::AsciiExt; +use std::str::FromStr; + +extern crate datetime; +use datetime::local; + +extern crate regex; +use regex::Regex; + +#[macro_use] +extern crate lazy_static; + + +/// A set of regexes to test against. +/// +/// All of these regexes use the `(?x)` flag, which means they support +/// comments and whitespace directly in the regex string! +lazy_static! { + + /// Format of a Rule line: one capturing group per field. + static ref RULE_LINE: Regex = 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+) + $ "##).unwrap(); + + /// Format of a Day specification in a Rule. + static ref DAY_FIELD: Regex = Regex::new(r##"(?x) ^ + ( ?P \w+ ) + ( ?P [<>] = ) + ( ?P \d+ ) + $ "##).unwrap(); + + /// Format of an hour and a minute. + static ref HM_FIELD: Regex = Regex::new(r##"(?x) ^ + ( ?P \d{1,2} ) : ( ?P \d{2} ) + ( ?P [wsugz] )? + $ "##).unwrap(); + + /// Format of an hour, a minute, and a second. + static ref HMS_FIELD: Regex = Regex::new(r##"(?x) ^ + ( ?P \d{1,2} ) : ( ?P \d{2} ) : ( ?P \d{2} ) + ( ?P [wsugz] )? + $ "##).unwrap(); + + /// Format of a Zone line, with one capturing group per field. + static ref ZONE_LINE: Regex = Regex::new(r##"(?x) ^ + Zone \s+ + ( ?P [ A-Z a-z / ]+ ) \s+ + ( ?P \S+ ) \s+ + ( ?P \S+ ) \s+ + ( ?P \S+ ) \s* + ( ?P \S+ )? \s* + ( ?P \S+ )? \s* + ( ?P \S+ )? \s* + ( ?P