Template Variable Expansion
Asked at Google
Reported by the problem's creator, not verified
A template engine fills in %key% placeholders. Template(mappings) is built once from a list of [key, value] pairs. render(source) returns source with its placeholders filled in, or the string "ERROR" when it cannot. Every render call is independent: an "ERROR" result says nothing about later calls.
Examples
Example 1
Input: init =
[[["user","ada"],["dir","docs"],["a","x"],["b","y"]]], operations =[["render",["/home/%user%/%dir%/%user%.txt"]],["render",["no placeholders"]],["render",["%a%-%b%"]],["render",["%user%"]]]Output:
["/home/ada/docs/ada.txt","no placeholders","x-y","ada"]Explanation: Each
%key%is replaced by its value, and a key may appear more than once. A source with no placeholders is returned unchanged.