Fix parsing of floats
This commit is contained in:
@@ -52,7 +52,7 @@ impl Machine {
|
||||
.iter()
|
||||
// 4. Trim and remove empty lines
|
||||
.map(|s| s.trim())
|
||||
.map(|s| s.replace(".", ""))
|
||||
.map(|s| if s.ends_with(".") { s[..s.len()-1].to_string() } else { s.to_string() })
|
||||
.filter(|s| !s.is_empty())
|
||||
// 5. Parse into QueryResolutionLine
|
||||
.map(QueryResolutionLine::try_from)
|
||||
|
||||
@@ -163,7 +163,13 @@ impl TryFrom<String> for Value {
|
||||
fn try_from(string: String) -> Result<Self, Self::Error> {
|
||||
let trimmed = string.trim();
|
||||
|
||||
if trimmed.starts_with("'") && trimmed.ends_with("'") {
|
||||
if let Ok(float_value) = string.parse::<f64>() {
|
||||
println!("float value: {} -> {}", string, float_value);
|
||||
Ok(Value::Float(OrderedFloat(float_value)))
|
||||
} else if let Ok(int_value) = string.parse::<i128>() {
|
||||
println!("int value: {} -> {}", string, int_value);
|
||||
Ok(Value::Integer(int_value.into()))
|
||||
} else if trimmed.starts_with("'") && trimmed.ends_with("'") {
|
||||
Ok(Value::String(trimmed[1..trimmed.len() - 1].into()))
|
||||
} else if trimmed.starts_with("\"") && trimmed.ends_with("\"") {
|
||||
Ok(Value::String(trimmed[1..trimmed.len() - 1].into()))
|
||||
|
||||
Reference in New Issue
Block a user