diff options
Diffstat (limited to 'tex/context/base/regi-ini.lua')
-rw-r--r-- | tex/context/base/regi-ini.lua | 72 |
1 files changed, 57 insertions, 15 deletions
diff --git a/tex/context/base/regi-ini.lua b/tex/context/base/regi-ini.lua index ec6f812cc..f9507bd0b 100644 --- a/tex/context/base/regi-ini.lua +++ b/tex/context/base/regi-ini.lua @@ -12,11 +12,13 @@ if not modules then modules = { } end modules ['regi-ini'] = { runtime.</p> --ldx]]-- -local utfchar, utfgsub = utf.char, utf.gsub +local commands, context = commands, context + +local utfchar = utf.char +local lpegmatch = lpeg.match local char, gsub, format = string.char, string.gsub, string.format local next = next -local insert, remove = table.insert, table.remove - +local insert, remove, fastcopy = table.insert, table.remove, table.fastcopy local allocate = utilities.storage.allocate local sequencers = utilities.sequencers @@ -138,17 +140,51 @@ local function translate(line,regime) return line end +-- local remappers = { } +-- +-- local function toregime(vector,str,default) -- toregime('8859-1',"abcde Ä","?") +-- local t = backmapping[vector] +-- local remapper = remappers[vector] +-- if not remapper then +-- remapper = utf.remapper(t) +-- remappers[t] = remapper +-- end +-- local m = getmetatable(t) +-- setmetatableindex(t, function(t,k) +-- local v = default or "?" +-- t[k] = v +-- return v +-- end) +-- str = remapper(str) +-- setmetatable(t,m) +-- return str +-- end +-- +-- -- much faster (but only matters when we have > 10K calls + +local cache = { } -- if really needed we can copy vectors and hash defaults + +setmetatableindex(cache, function(t,k) + local v = { remappers = { } } + t[k] = v + return v +end) + local function toregime(vector,str,default) -- toregime('8859-1',"abcde Ä","?") - local t = backmapping[vector] - local m = getmetatable(t) - setmetatableindex(t, function(t,k) - local v = default or "?" - t[k] = v - return v - end) - str = utfgsub(str,".",t) - setmetatable(t,m) - return str + local d = default or "?" + local c = cache[vector].remappers + local r = c[d] + if not r then + local t = fastcopy(backmapping[vector]) + setmetatableindex(t, function(t,k) + local v = d + t[k] = v + return v + end) + r = utf.remapper(t) + c[d] = r + end + return r(str) end local function disable() @@ -186,14 +222,14 @@ function regimes.process(str,filename,currentline,noflines,coding) return str end -function regimes.push() +local function push() level = level + 1 if trace_translating then report_translating("pushing level: %s",level) end end -function regimes.pop() +local function pop() if level > 0 then if trace_translating then report_translating("popping level: %s",level) @@ -202,6 +238,9 @@ function regimes.pop() end end +regimes.push = push +regimes.pop = pop + sequencers.prependaction(textlineactions,"system","regimes.process") sequencers.disableaction(textlineactions,"regimes.process") @@ -210,6 +249,9 @@ sequencers.disableaction(textlineactions,"regimes.process") commands.enableregime = enable commands.disableregime = disable +commands.pushregime = push +commands.popregime = pop + function commands.currentregime() context(currentregime) end |