From 021bb96aeb8b6bcbd93b5cdd309eaecd064d5a4c Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Mon, 4 Mar 2024 10:16:48 -0800 Subject: [PATCH] Allow non-string types to be used in "in" expressions (#211) * Allow non-string types to be used in "in" expressions * No unidecode smashing in "in" expressions, though! * Update version and changelog --- CHANGELOG.md | 4 ++++ evaluator.cpp | 15 +++++++-------- version.hpp | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea4cd87cc..0a9a0f985 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.49.0 + +* FSL-style "in" expressions now allow numeric comparisons, but they no longer use unidecode to remove diacritics. + # 2.48.0 * Fix some undefined behavior bugs, one of which results in slight changes to line simplification choices diff --git a/evaluator.cpp b/evaluator.cpp index a027ef3aa..a2d2a03a7 100644 --- a/evaluator.cpp +++ b/evaluator.cpp @@ -387,22 +387,21 @@ static int eval(std::function feature, json_obje if (f->value.array.array[2]->type == JSON_ARRAY && (strcmp(f->value.array.array[1]->value.string.string, "in") == 0 || strcmp(f->value.array.array[1]->value.string.string, "ni") == 0)) { - std::string s = mvt_value_to_string(lhs, fail, unidecode_data); + static std::vector no_unidecode_data; + std::string s = mvt_value_to_string(lhs, fail, no_unidecode_data); if (fail) { return -1; // null in anything => false } bool contains = false; for (size_t i = 0; i < f->value.array.array[2]->value.array.length; i++) { - if (f->value.array.array[2]->value.array.array[i]->type != JSON_STRING) { - return -1; // anything in [not-a-string] => null - } - - if (unidecode_data.size() > 0) { - smash(unidecode_data, f->value.array.array[2]->value.array.array[i]); + fail = false; + int cmp = compare_fsl(ff, f->value.array.array[2]->value.array.array[i], fail, no_unidecode_data); + if (fail) { + continue; // null } - if (strcmp(s.c_str(), f->value.array.array[2]->value.array.array[i]->value.string.string) == 0) { + if (cmp == 0) { contains = true; break; } diff --git a/version.hpp b/version.hpp index 067601290..91a0dc18f 100644 --- a/version.hpp +++ b/version.hpp @@ -1,6 +1,6 @@ #ifndef VERSION_HPP #define VERSION_HPP -#define VERSION "v2.48.0" +#define VERSION "v2.49.0" #endif