Extract filter_value_as_f64 helper in compare_json_value
Flattens the Number arm's nested target-coercion match into a one-line comparison, matching the shape of the String arm. No behavior change. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TeyhRfMYjMditek6geDRoQ
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
f96de8f38d
commit
564a0e8b2a
@@ -101,18 +101,19 @@ pub(crate) fn eval_json_comparison(text: &str, field: &str, op: CompareOp, value
|
||||
compare_json_value(field_value, op, value)
|
||||
}
|
||||
|
||||
fn compare_json_value(field_value: &serde_json::Value, op: CompareOp, value: &FilterValue) -> bool {
|
||||
match field_value {
|
||||
serde_json::Value::Number(n) => {
|
||||
let target = match value {
|
||||
fn filter_value_as_f64(value: &FilterValue) -> Option<f64> {
|
||||
match value {
|
||||
FilterValue::Number(v) => Some(*v),
|
||||
FilterValue::Raw(raw) => raw.parse::<f64>().ok(),
|
||||
};
|
||||
match (n.as_f64(), target) {
|
||||
(Some(f), Some(v)) => f.partial_cmp(&v).is_some_and(|ordering| op.matches(ordering)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn compare_json_value(field_value: &serde_json::Value, op: CompareOp, value: &FilterValue) -> bool {
|
||||
match field_value {
|
||||
serde_json::Value::Number(n) => matches!(
|
||||
(n.as_f64(), filter_value_as_f64(value)),
|
||||
(Some(f), Some(v)) if f.partial_cmp(&v).is_some_and(|ordering| op.matches(ordering))
|
||||
),
|
||||
serde_json::Value::String(s) => {
|
||||
let target = match value {
|
||||
FilterValue::Raw(raw) => raw.clone(),
|
||||
|
||||
Reference in New Issue
Block a user