diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2013-06-10 16:34:11 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2013-06-10 16:34:11 +0200 |
commit | f2f35fe3d8a1c5ce74ddbb8eef3cad2b18a379dc (patch) | |
tree | 87f4fd59a9cc436033822488309bf3da13426fdb /lualibs-util-tpl.lua | |
parent | 40cf2319dbf8b2d6796c7941a31795cd2cb55eb3 (diff) | |
download | lualibs-f2f35fe3d8a1c5ce74ddbb8eef3cad2b18a379dc.tar.gz |
sync with Context as of 2013-06-10
Diffstat (limited to 'lualibs-util-tpl.lua')
-rw-r--r-- | lualibs-util-tpl.lua | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lualibs-util-tpl.lua b/lualibs-util-tpl.lua index 511076b..dcc4c12 100644 --- a/lualibs-util-tpl.lua +++ b/lualibs-util-tpl.lua @@ -18,7 +18,7 @@ local report_template = logs.reporter("template") local tostring = tostring local format, sub = string.format, string.sub -local P, C, Cs, Carg, lpegmatch = lpeg.P, lpeg.C, lpeg.Cs, lpeg.Carg, lpeg.match +local P, C, Cs, Carg, lpegmatch, lpegpatterns = lpeg.P, lpeg.C, lpeg.Cs, lpeg.Carg, lpeg.match, lpeg.patterns -- todo: make installable template.new @@ -52,7 +52,10 @@ local sqlescape = lpeg.replacer { -- { "\t", "\\t" }, } -local sqlquotedescape = lpeg.Cs(lpeg.Cc("'") * sqlescape * lpeg.Cc("'")) +local sqlquoted = lpeg.Cs(lpeg.Cc("'") * sqlescape * lpeg.Cc("'")) + +lpegpatterns.sqlescape = sqlescape +lpegpatterns.sqlquoted = sqlquoted -- escapeset : \0\1\2\3\4\5\6\7\8\9\10\11\12\13\14\15\16\17\18\19\20\21\22\23\24\25\26\27\28\29\30\31\"\\\127 -- test string: [[1\0\31test23"\\]] .. string.char(19) .. "23" @@ -78,9 +81,16 @@ local sqlquotedescape = lpeg.Cs(lpeg.Cc("'") * sqlescape * lpeg.Cc("'")) -- P(1) -- )^0) +-- local xmlescape = lpegpatterns.xmlescape +-- local texescape = lpegpatterns.texescape +-- local luaescape = lpegpatterns.luaescape +-- local sqlquoted = lpegpatterns.sqlquoted +-- local luaquoted = lpegpatterns.luaquoted + local escapers = { lua = function(s) - return sub(format("%q",s),2,-2) + -- return sub(format("%q",s),2,-2) + return lpegmatch(luaescape,s) end, sql = function(s) return lpegmatch(sqlescape,s) @@ -89,16 +99,14 @@ local escapers = { local quotedescapers = { lua = function(s) + -- return lpegmatch(luaquoted,s) return format("%q",s) end, sql = function(s) - return lpegmatch(sqlquotedescape,s) + return lpegmatch(sqlquoted,s) end, } -lpeg.patterns.sqlescape = sqlescape -lpeg.patterns.sqlquotedescape = sqlquotedescape - local luaescaper = escapers.lua local quotedluaescaper = quotedescapers.lua |