Merge pull request #206 from matthiasbeyer/regex-lazy-static
Regex lazy static
This commit is contained in:
commit
be45c4eb14
6 changed files with 22 additions and 13 deletions
|
@ -6,6 +6,7 @@ authors = ["Matthias Beyer <mail@beyermatthias.de>"]
|
|||
[dependencies]
|
||||
fs2 = "0.2.2"
|
||||
glob = "0.2.10"
|
||||
lazy_static = "0.1.15"
|
||||
log = "0.3.5"
|
||||
regex = "0.1.47"
|
||||
semver = "0.2"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#[macro_use] extern crate version;
|
||||
extern crate fs2;
|
||||
extern crate glob;
|
||||
#[macro_use] extern crate lazy_static;
|
||||
extern crate regex;
|
||||
extern crate toml;
|
||||
#[cfg(test)] extern crate tempdir;
|
||||
|
|
|
@ -870,14 +870,16 @@ impl Entry {
|
|||
|
||||
pub fn from_str(loc: StoreId, s: &str) -> Result<Entry> {
|
||||
debug!("Building entry from string");
|
||||
let re = Regex::new(r"(?smx)
|
||||
lazy_static! {
|
||||
static ref RE: Regex = Regex::new(r"(?smx)
|
||||
^---$
|
||||
(?P<header>.*) # Header
|
||||
^---$\n
|
||||
(?P<content>.*) # Content
|
||||
").unwrap();
|
||||
}
|
||||
|
||||
let matches = re.captures(s);
|
||||
let matches = RE.captures(s);
|
||||
|
||||
if matches.is_none() {
|
||||
return Err(StoreError::new(StoreErrorKind::MalformedEntry, None));
|
||||
|
|
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
|||
authors = ["Matthias Beyer <mail@beyermatthias.de>"]
|
||||
|
||||
[dependencies]
|
||||
lazy_static = "0.1.15"
|
||||
log = "0.3.5"
|
||||
regex = "0.1.47"
|
||||
|
||||
|
|
|
@ -43,16 +43,19 @@ impl IntoKeyValue<String, String> for String {
|
|||
|
||||
fn into_kv(self) -> Option<KeyValue<String, String>> {
|
||||
let key = {
|
||||
let r = "^(?P<KEY>([^=]*))=(.*)$";
|
||||
let r = Regex::new(r).unwrap();
|
||||
r.captures(&self[..])
|
||||
lazy_static! {
|
||||
static ref R: Regex = Regex::new("^(?P<KEY>([^=]*))=(.*)$").unwrap();
|
||||
}
|
||||
R.captures(&self[..])
|
||||
.and_then(|caps| caps.name("KEY"))
|
||||
};
|
||||
|
||||
let value = {
|
||||
let r = "(.*)=(\"(?P<QVALUE>([^\"]*))\"|(?P<VALUE>(.*)))$";
|
||||
let r = Regex::new(r).unwrap();
|
||||
r.captures(&self[..])
|
||||
lazy_static! {
|
||||
static ref R: Regex = Regex::new("(.*)=(\"(?P<QVALUE>([^\"]*))\"|(?P<VALUE>(.*)))$")
|
||||
.unwrap();
|
||||
}
|
||||
R.captures(&self[..])
|
||||
.map(|caps| {
|
||||
caps.name("VALUE")
|
||||
.or(caps.name("QVALUE"))
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#[macro_use] extern crate lazy_static;
|
||||
#[macro_use] extern crate log;
|
||||
extern crate regex;
|
||||
|
||||
|
|
Loading…
Reference in a new issue