diff --git a/libimagutil/Cargo.toml b/libimagutil/Cargo.toml index 6e442b18..3e7d82f8 100644 --- a/libimagutil/Cargo.toml +++ b/libimagutil/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Matthias Beyer "] [dependencies] +lazy_static = "0.1.15" log = "0.3.5" regex = "0.1.47" diff --git a/libimagutil/src/key_value_split.rs b/libimagutil/src/key_value_split.rs index 796f0c82..b5e2790e 100644 --- a/libimagutil/src/key_value_split.rs +++ b/libimagutil/src/key_value_split.rs @@ -43,16 +43,19 @@ impl IntoKeyValue for String { fn into_kv(self) -> Option> { let key = { - let r = "^(?P([^=]*))=(.*)$"; - let r = Regex::new(r).unwrap(); - r.captures(&self[..]) + lazy_static! { + static ref R: Regex = Regex::new("^(?P([^=]*))=(.*)$").unwrap(); + } + R.captures(&self[..]) .and_then(|caps| caps.name("KEY")) }; let value = { - let r = "(.*)=(\"(?P([^\"]*))\"|(?P(.*)))$"; - let r = Regex::new(r).unwrap(); - r.captures(&self[..]) + lazy_static! { + static ref R: Regex = Regex::new("(.*)=(\"(?P([^\"]*))\"|(?P(.*)))$") + .unwrap(); + } + R.captures(&self[..]) .map(|caps| { caps.name("VALUE") .or(caps.name("QVALUE")) diff --git a/libimagutil/src/lib.rs b/libimagutil/src/lib.rs index a7586143..0b74fc2d 100644 --- a/libimagutil/src/lib.rs +++ b/libimagutil/src/lib.rs @@ -1,3 +1,4 @@ +#[macro_use] extern crate lazy_static; #[macro_use] extern crate log; extern crate regex;