From 613f72e76919e0f6662186ce2106945a65a050a7 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 17 Apr 2024 19:30:11 +0200 Subject: [PATCH] Refactoring --- .../java/eu/faircode/email/EntityRule.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index 638a860b2b..794b7a7784 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -673,23 +673,25 @@ public class EntityRule { public EvaluationValue evaluate( Expression expression, Token operatorToken, EvaluationValue... operands) { Log.i("EXPR " + operands[0] + (regex ? " MATCHES " : " CONTAINS ") + operands[1] + " regex=" + regex); + String condition = operands[1].getStringValue(); List array = operands[0].getArrayValue(); - if (!TextUtils.isEmpty(condition) && array != null) { - Pattern p = (regex ? Pattern.compile(condition, Pattern.DOTALL) : null); - Log.i("EXPR regex=" + (p == null ? null : p.pattern())); - for (EvaluationValue item : array) { - String value = item.getStringValue(); - if (!TextUtils.isEmpty(value)) - if (p == null) { - if (value.toLowerCase().contains(condition.toLowerCase())) - return expression.convertValue(true); - } else { - if (p.matcher(value).matches()) - return expression.convertValue(true); - } - } + if (TextUtils.isEmpty(condition) || array == null || array.isEmpty()) + return expression.convertValue(false); + + Pattern p = (regex ? Pattern.compile(condition, Pattern.DOTALL) : null); + for (EvaluationValue item : array) { + String value = item.getStringValue(); + if (!TextUtils.isEmpty(value)) + if (p == null) { + if (value.toLowerCase().contains(condition.toLowerCase())) + return expression.convertValue(true); + } else { + if (p.matcher(value).matches()) + return expression.convertValue(true); + } } + return expression.convertValue(false); } }