summaryrefslogtreecommitdiff
path: root/lualibs-util-str.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-06-10 16:34:11 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2013-06-10 16:34:11 +0200
commitf2f35fe3d8a1c5ce74ddbb8eef3cad2b18a379dc (patch)
tree87f4fd59a9cc436033822488309bf3da13426fdb /lualibs-util-str.lua
parent40cf2319dbf8b2d6796c7941a31795cd2cb55eb3 (diff)
downloadlualibs-f2f35fe3d8a1c5ce74ddbb8eef3cad2b18a379dc.tar.gz
sync with Context as of 2013-06-10
Diffstat (limited to 'lualibs-util-str.lua')
-rw-r--r--lualibs-util-str.lua14
1 files changed, 10 insertions, 4 deletions
diff --git a/lualibs-util-str.lua b/lualibs-util-str.lua
index 10456a7..0c8c0e2 100644
--- a/lualibs-util-str.lua
+++ b/lualibs-util-str.lua
@@ -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:
--