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