name = "tidy"
version = "0.1.0"
dependencies = [
+ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
use std::io::prelude::*;
use std::path::Path;
-use regex::{Regex, escape};
+use regex::Regex;
mod version;
use version::Version;
}
fn find_attr_val<'a>(line: &'a str, attr: &str) -> Option<&'a str> {
- let r = Regex::new(&format!(r#"{}\s*=\s*"([^"]*)""#, escape(attr)))
- .expect("malformed regex for find_attr_val");
+ lazy_static::lazy_static! {
+ static ref ISSUE: Regex = Regex::new(r#"issue\s*=\s*"([^"]*)""#).unwrap();
+ static ref FEATURE: Regex = Regex::new(r#"feature\s*=\s*"([^"]*)""#).unwrap();
+ static ref SINCE: Regex = Regex::new(r#"since\s*=\s*"([^"]*)""#).unwrap();
+ }
+
+ let r = match attr {
+ "issue" => &*ISSUE,
+ "feature" => &*FEATURE,
+ "since" => &*SINCE,
+ _ => unimplemented!("{} not handled", attr),
+ };
+
r.captures(line)
.and_then(|c| c.get(1))
.map(|m| m.as_str())