summaryrefslogtreecommitdiff
path: root/lualibs-util-str.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-07-23 14:50:58 -0700
committerPhilipp Gesang <phg42.2a@gmail.com>2013-07-23 14:50:58 -0700
commitd287bf5f8bc24ad366a3ff8e07dcb93d0f48bd03 (patch)
treeede13cd011ffb59c4bd165a55a703f5ddf41a153 /lualibs-util-str.lua
parent32b7ab871a07f20c73187a577dedb737cc8b18fd (diff)
parentf2f3234465dd965a9915b97bc8b3ac77bd40c464 (diff)
downloadlualibs-d287bf5f8bc24ad366a3ff8e07dcb93d0f48bd03.tar.gz
Merge pull request #15 from phi-gamma/master
update to 2.0c
Diffstat (limited to 'lualibs-util-str.lua')
-rw-r--r--lualibs-util-str.lua16
1 files changed, 11 insertions, 5 deletions
diff --git a/lualibs-util-str.lua b/lualibs-util-str.lua
index 10456a7..13e1e09 100644
--- a/lualibs-util-str.lua
+++ b/lualibs-util-str.lua
@@ -339,7 +339,7 @@ local format_i = function(f)
if f and f ~= "" then
return format("format('%%%si',a%s)",f,n)
else
- return format("a%s",n)
+ return format("format('%%i',a%s)",n)
end
end
@@ -735,11 +735,17 @@ strings.formatters.add = add
-- registered in the default instance (should we fall back on this one?)
-lpeg.patterns.xmlescape = Cs((P("<")/"&lt;" + P(">")/"&gt;" + P("&")/"&amp;" + P('"')/"&quot;" + P(1))^0)
-lpeg.patterns.texescape = Cs((C(S("#$%\\{}"))/"\\%1" + P(1))^0)
+patterns.xmlescape = Cs((P("<")/"&lt;" + P(">")/"&gt;" + P("&")/"&amp;" + P('"')/"&quot;" + P(1))^0)
+patterns.texescape = Cs((C(S("#$%\\{}"))/"\\%1" + P(1))^0)
+patterns.luaescape = Cs(((1-S('"\n'))^1 + P('"')/'\\"' + P('\n')/'\\n"')^0) -- maybe also \0
+patterns.luaquoted = Cs(Cc('"') * ((1-S('"\n'))^1 + P('"')/'\\"' + P('\n')/'\\n"')^0 * Cc('"'))
-add(formatters,"xml",[[lpegmatch(xmlescape,%s)]],[[local xmlescape = lpeg.patterns.xmlescape]])
-add(formatters,"tex",[[lpegmatch(texescape,%s)]],[[local texescape = lpeg.patterns.texescape]])
+-- escaping by lpeg is faster for strings without quotes, slower on a string with quotes, but
+-- faster again when other q-escapables are found (the ones we don't need to escape)
+
+add(formatters,"xml", [[lpegmatch(xmlescape,%s)]],[[local xmlescape = lpeg.patterns.xmlescape]])
+add(formatters,"tex", [[lpegmatch(texescape,%s)]],[[local texescape = lpeg.patterns.texescape]])
+add(formatters,"lua", [[lpegmatch(luaescape,%s)]],[[local luaescape = lpeg.patterns.luaescape]])
-- -- yes or no:
--