From c5469ba6723eaecc5797acc842d090e1b85afb60 Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Fri, 20 Mar 2020 14:55:50 +0100 Subject: add filter: length --- src/template.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/template.c b/src/template.c index f85db25..cf021c1 100644 --- a/src/template.c +++ b/src/template.c @@ -666,11 +666,20 @@ struct unja_object *filter_wordcount(struct unja_object *obj) { return make_int_object(word_count); } + +struct unja_object *filter_length(struct unja_object *obj) { + assert(obj->type == OBJ_STRING); + int len = strlen(obj->string); + object_free(obj); + return make_int_object(len); +} + struct hashmap *default_filters() { struct hashmap *filters = hashmap_new(); hashmap_insert(filters, "trim", filter_trim); hashmap_insert(filters, "lower", filter_lower); hashmap_insert(filters, "wordcount", filter_wordcount); + hashmap_insert(filters, "length", filter_length); return filters; } -- cgit v1.2.3