forked from pyrex/chameleonic
fix section before first "%"
oops, need to special-case the first part of the split list. amusingly, I don't need to special-case zero-length format strings because that will skip the entire loop and output "", which seems correct. (I am also not special-casing zero-length segments because `s[1] == nil` will go into the error handler and that seems fine.
This commit is contained in:
parent
2ce259304d
commit
367f03be4a
@ -44,8 +44,13 @@ end
|
|||||||
-- %! for tostring(param)
|
-- %! for tostring(param)
|
||||||
-- which dumps tables
|
-- which dumps tables
|
||||||
function fmt(f, ...)
|
function fmt(f, ...)
|
||||||
local out, i = "", 1
|
local out, i = "", 0
|
||||||
for s in all(split(f,"%")) do
|
for s in all(split(f,"%")) do
|
||||||
|
if i == 0 then
|
||||||
|
-- before first format directive
|
||||||
|
out ..= s
|
||||||
|
i = 1
|
||||||
|
else
|
||||||
local m = s[1]
|
local m = s[1]
|
||||||
if m == "~" then
|
if m == "~" then
|
||||||
out ..= "%"
|
out ..= "%"
|
||||||
@ -62,6 +67,7 @@ function fmt(f, ...)
|
|||||||
end
|
end
|
||||||
out ..=sub(s,2)
|
out ..=sub(s,2)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user