Skip to content

A simple template/replace for erlang lists/strings

Notifications You must be signed in to change notification settings

peffis/template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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}

About

A simple template/replace for erlang lists/strings

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published