diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-01-31 12:54:59 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-02-09 13:45:13 +0100 |
commit | 10fa3e3dafd3b44623b863344e562e80209e53fb (patch) | |
tree | 0a7576b43379e03883e4009c23a33d7a9e881bd1 /imag-store | |
parent | 5fdbb61ac850d41c5c6cb4618ecec26dadbffc77 (diff) |
util: Add parsing ints and floats
Diffstat (limited to 'imag-store')
-rw-r--r-- | imag-store/src/util.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/imag-store/src/util.rs b/imag-store/src/util.rs index 0c033535..d339dc6f 100644 --- a/imag-store/src/util.rs +++ b/imag-store/src/util.rs @@ -76,6 +76,8 @@ fn insert_key_into(current: String, } fn parse_value(value: String) -> Value { + use std::str::FromStr; + fn is_ary(v: &String) -> bool { v.chars().next() == Some('[') && v.chars().last() == Some(']') && v.len() >= 3 } @@ -91,8 +93,22 @@ fn parse_value(value: String) -> Value { let sub = &value[1..(value.len()-1)]; Value::Array(sub.split(",").map(|v| parse_value(String::from(v))).collect()) } else { - debug!("Building String out of: {:?}...", value); - Value::String(value) + FromStr::from_str(&value[..]) + .map(|i: i64| { + debug!("Building Integer out of: {:?}...", value); + Value::Integer(i) + }) + .unwrap_or_else(|_| { + FromStr::from_str(&value[..]) + .map(|f: f64| { + debug!("Building Float out of: {:?}...", value); + Value::Float(f) + }) + .unwrap_or_else(|_| { + debug!("Building String out of: {:?}...", value); + Value::String(value) + }) + }) } } |