diff options
author | Robin Jarry <robin@jarry.cc> | 2023-03-04 01:12:23 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-03-08 00:43:02 +0100 |
commit | 56a6ed0cf71ecf55f37e94b574c41927452abc44 (patch) | |
tree | 9d18955520db78247b1a62a8d79121b0b63974ce /lib/templates/functions.go | |
parent | 573b3266afcf6dc52c82ffa238f5d9b82ee11cf7 (diff) | |
download | aerc-56a6ed0cf71ecf55f37e94b574c41927452abc44.tar.gz |
templates: add match function
Add a match function that returns true if a string matches the provided
regular expression. The compiled regular expressions are cached in
a sync.Map to avoid repetitive compilations of the same expressions.
Caveat: if the user mixes the arguments order, it may cause the cache to
consume a lot of memory filled with garbage regular expression objects.
Ideally, we would need to limit the size of this cache and/or use a LRU
cache implementation. Maybe someday?
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'lib/templates/functions.go')
-rw-r--r-- | lib/templates/functions.go | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/templates/functions.go b/lib/templates/functions.go index 1cbdc85d..8bd8f37b 100644 --- a/lib/templates/functions.go +++ b/lib/templates/functions.go @@ -11,6 +11,7 @@ import ( "time" "git.sr.ht/~rjarry/aerc/lib/format" + "git.sr.ht/~rjarry/aerc/lib/parse" "github.com/emersion/go-message/mail" ) @@ -271,4 +272,5 @@ var templateFuncs = template.FuncMap{ "join": join, "trimSignature": trimSignature, "compactDir": compactDir, + "match": parse.MatchCache, } |