Add len function to notification expressions

This commit is contained in:
JonnyWong16 2021-06-09 15:40:35 -07:00
commit dff9a56950
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
3 changed files with 9 additions and 0 deletions

View file

@ -1929,6 +1929,7 @@ Rating: {rating}/10 --> Rating: /10
<li><span class="inline-pre">divmod(a, b)</span></li>
<li><span class="inline-pre">float(x)</span></li>
<li><span class="inline-pre">int(x)</span></li>
<li><span class="inline-pre">len(s)</span></li>
<li><span class="inline-pre">round(n[, ndigits])</span></li>
<li><span class="inline-pre">str(x)</span></li>
</ul>

View file

@ -537,6 +537,13 @@ def helper_divmod(a, b):
return 0
def helper_len(s):
try:
return len(s)
except (ValueError, TypeError):
return 0
def helper_round(n, ndigits=None):
try:
return round(n, ndigits)

View file

@ -1825,6 +1825,7 @@ def str_eval(field_name, kwargs):
'divmod': helpers.helper_divmod,
'float': helpers.cast_to_float,
'int': helpers.cast_to_int,
'len': helpers.helper_len,
'round': helpers.helper_round,
'str': str
}