[added] stringx.apply_template for "$template_var" containing strings

This commit is contained in:
Max Cahill 2020-11-19 17:18:38 +11:00
parent 01ffdc09cd
commit 8be736d992

View File

@ -272,4 +272,12 @@ end
--alias
stringx.dedent = stringx.deindent
--apply a template to a string
--supports $template style values, given as a table or function
-- ie ("hello $name"):format({name = "tom"}) == "hello tom"
function stringx.apply_template(s, sub)
local r = s:gsub("%$(%w+)", sub)
return r
end
return stringx