A simple template/replace for erlang lists/strings
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
doc
src
.gitignore
Makefile
README.md
erlang.mk

README.md

template

A simple template/replace for erlang lists/strings

usage

replacing variables in the template given a dictionary

2> template:replace("Hello $(NAME)", #{"NAME" => "John Doe"}).
"Hello John Doe"
3> template:replace("Hello $(GIVEN_NAME) $(SURNAME)", #{"GIVEN_NAME" => "John", "SURNAME" => "Doe"}).
"Hello John Doe"
4> template:replace("Hello $(NAME)", #{}).
{error,{bad_key,"NAME"}}
5> template:replace("Hello $(NAME", #{"NAME" => "John"}).
{error,eof}

matching template with string producing a dictionary

2> template:match("$(A)bc", "abc").
#{"A" => "a"}
3> template:match("a$(A)$(A)a", "abba").
#{"A" => "b"}
4> template:match("$(A)bcd$(B)", "bcde").
#{"A" => [],"B" => "e"}
5> template:match("$(A)bc$(A)", "abcd").
{error,no_match}
6> template:match("$(A)bc$(A", "abcd").
{error,eof}