Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 952 Bytes

README.md

File metadata and controls

53 lines (41 loc) · 952 Bytes

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}