summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/luaotfload/fontloader-util-str.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luaotfload/fontloader-util-str.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/luaotfload/fontloader-util-str.lua59
1 files changed, 56 insertions, 3 deletions
diff --git a/Master/texmf-dist/tex/luatex/luaotfload/fontloader-util-str.lua b/Master/texmf-dist/tex/luatex/luaotfload/fontloader-util-str.lua
index 0d1f39de9d7..b5c721a41d2 100644
--- a/Master/texmf-dist/tex/luatex/luaotfload/fontloader-util-str.lua
+++ b/Master/texmf-dist/tex/luatex/luaotfload/fontloader-util-str.lua
@@ -10,12 +10,13 @@ utilities = utilities or { }
utilities.strings = utilities.strings or { }
local strings = utilities.strings
-local format, gsub, rep, sub, find = string.format, string.gsub, string.rep, string.sub, string.find
+local format, gsub, rep, sub, find, char = string.format, string.gsub, string.rep, string.sub, string.find, string.char
local load, dump = load, string.dump
local tonumber, type, tostring, next, setmetatable = tonumber, type, tostring, next, setmetatable
local unpack, concat = table.unpack, table.concat
local P, V, C, S, R, Ct, Cs, Cp, Carg, Cc = lpeg.P, lpeg.V, lpeg.C, lpeg.S, lpeg.R, lpeg.Ct, lpeg.Cs, lpeg.Cp, lpeg.Carg, lpeg.Cc
local patterns, lpegmatch = lpeg.patterns, lpeg.match
+local tsplitat = lpeg.tsplitat
local utfchar, utfbyte, utflen = utf.char, utf.byte, utf.len
----- loadstripped = utilities.lua.loadstripped
@@ -622,7 +623,7 @@ local template = [[
return function(%s) return %s end
]]
--- this might move
+-- We only use fast serialize in controlled cases.
local pattern = Cs(Cc('"') * (
(1-S('"\\\n\r'))^1
@@ -632,12 +633,43 @@ local pattern = Cs(Cc('"') * (
+ P('\r') / '\\r'
)^0 * Cc('"'))
+-- -- I need to do more experiments with this:
+--
+-- local pattern = Cs(Cc('"') * (
+-- (1-S('"\\\n\r'))^1
+-- + P('"') / '\\034'
+-- + P('\\') / '\\092'
+-- + P('\n') / '\\013'
+-- + P('\r') / '\\010'
+-- )^0 * Cc('"'))
+
patterns.escapedquotes = pattern
function string.escapedquotes(s)
return lpegmatch(pattern,s)
end
+local pattern = (1 - P("\\"))^1 ; pattern = Cs (
+ pattern
+ * ( (P("\\") / "" * (digit^-3 / function(s) return char(tonumber(s)) end)) + pattern )^1
+)
+
+patterns.unescapedquotes = pattern
+
+function string.unescapedquotes(s)
+ return lpegmatch(pattern,s) or s
+end
+
+-- function string.longifneeded(s)
+-- if find(s,'["\\\n\r]') then
+-- return "[===[" .. s .. "]===]"
+-- else
+-- return '"' .. s ..'"'
+-- end
+-- end
+
+string.texnewlines = lpeg.replacer(patterns.newline,"\r",true)
+
-- print(string.escapedquotes('1\\23\n"'))
-- but for now here
@@ -1476,7 +1508,7 @@ end
if not string.explode then
- local tsplitat = lpeg.tsplitat
+ -- local tsplitat = lpeg.tsplitat
local p_utf = patterns.utf8character
local p_check = C(p_utf) * (P("+") * Cc(true))^0
@@ -1499,3 +1531,24 @@ if not string.explode then
end
end
+
+
+do
+
+ local p_whitespace = patterns.whitespace^1
+
+ local cache = setmetatable({ }, { __index = function(t,k)
+ local p = tsplitat(p_whitespace * P(k) * p_whitespace)
+ local v = function(s)
+ return lpegmatch(p,s)
+ end
+ t[k] = v
+ return v
+ end })
+
+ function string.wordsplitter(s)
+ return cache[s]
+ end
+
+end
+