You are given:
s
that may contain
placeholders
delimited by the
%
character.
dict
mapping keys (strings) to replacement values (strings).
A placeholder is any substring that starts and ends with %, for example %key%. The text between the two % characters (here, key) is used as a lookup key in dict.
Example:
s = "a%sd%fasd%dog%sdfisan"
dict = { "sd": "HELLO", "dog": "CAT" }
Expected output:
"aHELLOfasdCATsdfisan"
s
from left to right.
%...%
is copied directly to the output.
%
, you start reading a key until the next
%
:
%
characters form the key.
dict
.
dict[key]
to the output.
dict
, the function should report an
error
(for example, by returning a special error value or throwing an exception; define your choice clearly in your solution).
%
characters are properly paired (no unmatched
%
).
%
(every
%
starts or ends a placeholder).
dict
.
s
(plus the cost of dictionary lookups).