Skip to content

peffis/template

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
doc
 
 
src
 
 
 
 
 
 
 
 
 
 

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