summaryrefslogtreecommitdiffstats
path: root/libimagutil
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-01-29 20:03:43 +0100
committerMatthias Beyer <mail@beyermatthias.de>2016-01-29 23:11:42 +0100
commit448c69891e29761e4199e5415b1ea4107446256d (patch)
treefa5df5d0b9a9517bcf50677dc33f6c47e8af0650 /libimagutil
parent33b6a89a022113fa332ad29083d2fbf2b4d5c0f0 (diff)
Reimplement IntoKeyValue for String
* Double quotes should not be in the result * Regex allows quotes in strings now
Diffstat (limited to 'libimagutil')
-rw-r--r--libimagutil/src/key_value_split.rs32
1 files changed, 22 insertions, 10 deletions
diff --git a/libimagutil/src/key_value_split.rs b/libimagutil/src/key_value_split.rs
index b928820b..0efb024f 100644
--- a/libimagutil/src/key_value_split.rs
+++ b/libimagutil/src/key_value_split.rs
@@ -42,16 +42,28 @@ pub trait IntoKeyValue<K, V> {
impl IntoKeyValue<String, String> for String {
fn into_kv(self) -> Option<KeyValue<String, String>> {
- let r = "^(?P<KEY>(.*))=((\"(?P<DOUBLE_QVAL>(.*))\")|(\'(?P<SINGLE_QVAL>(.*)))\'|(?P<VAL>[^\'\"](.*)[^\'\"]))$";
- let regex = Regex::new(r).unwrap();
- regex.captures(&self[..]).and_then(|cap| {
- cap.name("KEY")
- .map(|name| {
- cap.name("SINGLE_QVAL")
- .or(cap.name("DOUBLE_QVAL"))
- .or(cap.name("VAL"))
- .map(|value| KeyValue::new(String::from(name), String::from(value)))
- }).unwrap_or(None)
+ let key = {
+ let r = "^(?P<KEY>([^=]*))=(.*)$";
+ let r = Regex::new(r).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[..])
+ .map(|caps| {
+ caps.name("VALUE")
+ .or(caps.name("QVALUE"))
+ .unwrap_or("")
+ })
+ };
+
+ key.and_then(|k| {
+ value.and_then(|v| {
+ Some(KeyValue::new(String::from(k), String::from(v)))
+ })
})
}