Fix parsing of floats

This commit is contained in:
Nicolas Luck
2023-08-24 18:10:47 +02:00
parent bfb3164a0d
commit c25888288a
2 changed files with 8 additions and 2 deletions

View File

@@ -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()))