diff options
author | Hans Hagen <pragma@wxs.nl> | 2013-06-10 12:24:00 +0200 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2013-06-10 12:24:00 +0200 |
commit | b4a7a2353b029fcff03f5e3668d98ef61f03df3f (patch) | |
tree | 79b26772ecd40c741b7c8104c355cc019bb4e3c0 /tex/context/base/util-str.lua | |
parent | 06598aba33407bf903137696d65f2d7988e2748a (diff) | |
download | context-b4a7a2353b029fcff03f5e3668d98ef61f03df3f.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: -- |