diff options
author | Marius <mariausol@gmail.com> | 2013-06-10 14:00:23 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2013-06-10 14:00:23 +0300 |
commit | d9a4319a4f92ebac0b92663691cb73354f3a8e85 (patch) | |
tree | eb5a8efe86c4c7ac0ebb84c3575f70ad0f87ae30 /tex/context/base/util-str.lua | |
parent | a874c7d658c31400d3c6e74aff8a09f46989e1a4 (diff) | |
download | context-d9a4319a4f92ebac0b92663691cb73354f3a8e85.tar.gz |
beta 2013.06.10 12:24
Diffstat (limited to 'tex/context/base/util-str.lua')
-rw-r--r-- | tex/context/base/util-str.lua | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/tex/context/base/util-str.lua b/tex/context/base/util-str.lua index 10456a729..0c8c0e2d2 100644 --- a/tex/context/base/util-str.lua +++ b/tex/context/base/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("<")/"<" + P(">")/">" + P("&")/"&" + P('"')/""" + P(1))^0) -lpeg.patterns.texescape = Cs((C(S("#$%\\{}"))/"\\%1" + P(1))^0) +patterns.xmlescape = Cs((P("<")/"<" + P(">")/">" + P("&")/"&" + P('"')/""" + 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: -- |