Added expression function size()

pull/215/head
M66B 8 months ago
parent efff870d97
commit ad53d3d1ea

@ -2780,6 +2780,7 @@ The following extra functions are available:
* *hasMx()* (returns a boolean indicating if the from/reply-to address has an associated MX record; since version 1.2179)
* *attachments()* (returns an integer indicating number of attachments; since version 1.2179)
* *Jsoup()* (returns an array of selected strings; since version 1.2179)
* *Size(array)* (returns the number of items in an array; since version 1.2179)
Example conditions:

@ -94,6 +94,7 @@ public class ExpressionHelper {
MxFunction fMx = new MxFunction(context, message);
AttachmentsFunction fAttachments = new AttachmentsFunction(context, message);
JsoupFunction fJsoup = new JsoupFunction(context, message);
SizeFunction fSize = new SizeFunction();
ContainsOperator oContains = new ContainsOperator(false);
ContainsOperator oMatches = new ContainsOperator(true);
@ -107,6 +108,7 @@ public class ExpressionHelper {
configuration.getFunctionDictionary().addFunction("hasMx", fMx);
configuration.getFunctionDictionary().addFunction("attachments", fAttachments);
configuration.getFunctionDictionary().addFunction("Jsoup", fJsoup);
configuration.getFunctionDictionary().addFunction("Size", fSize);
configuration.getOperatorDictionary().addOperator("Contains", oContains);
configuration.getOperatorDictionary().addOperator("Matches", oMatches);
@ -343,6 +345,25 @@ public class ExpressionHelper {
}
}
@FunctionParameter(name = "value")
public static class SizeFunction extends AbstractFunction {
SizeFunction() {
}
@Override
public EvaluationValue evaluate(
Expression expression, Token functionToken, EvaluationValue... parameterValues) {
int result = 0;
if (parameterValues.length == 1 &&
parameterValues[0].getDataType() == EvaluationValue.DataType.ARRAY)
result = parameterValues[0].getArrayValue().size();
Log.i("EXPR size()=" + result);
return expression.convertValue(result);
}
}
@InfixOperator(precedence = OPERATOR_PRECEDENCE_COMPARISON)
public static class ContainsOperator extends AbstractOperator {
private final boolean regex;

@ -1521,6 +1521,7 @@ X-Google-Original-From: Somebody &lt;somebody+extra@example.org&gt;</code></pre>
<li><em>hasMx()</em> (returns a boolean indicating if the from/reply-to address has an associated MX record; since version 1.2179)</li>
<li><em>attachments()</em> (returns an integer indicating number of attachments; since version 1.2179)</li>
<li><em>Jsoup()</em> (returns an array of selected strings; since version 1.2179)</li>
<li><em>Size(array)</em> (returns the number of items in an array; since version 1.2179)</li>
</ul>
<p>Example conditions:</p>
<p><code>header("X-Mailer") contains "Open-Xchange" &amp;&amp; from matches ".*service@.*"</code></p>

Loading…
Cancel
Save