mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-26 07:34: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
|
--alias
|
||||||
stringx.dedent = stringx.deindent
|
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
|
return stringx
|
||||||
|
Loading…
Reference in New Issue
Block a user