mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-25 23:24:35 +00:00
[added] stringx.apply_template for "$template_var" containing strings
This commit is contained in:
parent
01ffdc09cd
commit
8be736d992
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user