summaryrefslogtreecommitdiff
path: root/tex/context/base/regi-ini.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/regi-ini.lua')
-rw-r--r--tex/context/base/regi-ini.lua72
1 files changed, 15 insertions, 57 deletions
diff --git a/tex/context/base/regi-ini.lua b/tex/context/base/regi-ini.lua
index f9507bd0b..ec6f812cc 100644
--- a/tex/context/base/regi-ini.lua
+++ b/tex/context/base/regi-ini.lua
@@ -12,13 +12,11 @@ if not modules then modules = { } end modules ['regi-ini'] = {
runtime.</p>
--ldx]]--
-local commands, context = commands, context
-
-local utfchar = utf.char
-local lpegmatch = lpeg.match
+local utfchar, utfgsub = utf.char, utf.gsub
local char, gsub, format = string.char, string.gsub, string.format
local next = next
-local insert, remove, fastcopy = table.insert, table.remove, table.fastcopy
+local insert, remove = table.insert, table.remove
+
local allocate = utilities.storage.allocate
local sequencers = utilities.sequencers
@@ -140,51 +138,17 @@ 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 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)
+ 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
end
local function disable()
@@ -222,14 +186,14 @@ function regimes.process(str,filename,currentline,noflines,coding)
return str
end
-local function push()
+function regimes.push()
level = level + 1
if trace_translating then
report_translating("pushing level: %s",level)
end
end
-local function pop()
+function regimes.pop()
if level > 0 then
if trace_translating then
report_translating("popping level: %s",level)
@@ -238,9 +202,6 @@ local function pop()
end
end
-regimes.push = push
-regimes.pop = pop
-
sequencers.prependaction(textlineactions,"system","regimes.process")
sequencers.disableaction(textlineactions,"regimes.process")
@@ -249,9 +210,6 @@ sequencers.disableaction(textlineactions,"regimes.process")
commands.enableregime = enable
commands.disableregime = disable
-commands.pushregime = push
-commands.popregime = pop
-
function commands.currentregime()
context(currentregime)
end