summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/regi-ini.lua
diff options
context:
space:
mode:
authorMojca Miklavec <mojca.miklavec@gmail.com>2012-05-14 17:38:55 +0000
committerMojca Miklavec <mojca.miklavec@gmail.com>2012-05-14 17:38:55 +0000
commit15995e10bfc68edf79970c4ea4fbb6678566c46e (patch)
tree2de7ca2a83f2d37ef043ad7429a5cb945bb79ddb /Master/texmf-dist/tex/context/base/regi-ini.lua
parentc9a39f716f1e5ec820ed3aab2c9aef25c5a9d730 (diff)
ConTeXt 2012.05.14 16:00
git-svn-id: svn://tug.org/texlive/trunk@26371 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/regi-ini.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/regi-ini.lua43
1 files changed, 38 insertions, 5 deletions
diff --git a/Master/texmf-dist/tex/context/base/regi-ini.lua b/Master/texmf-dist/tex/context/base/regi-ini.lua
index a440b65771a..ec6f812ccb1 100644
--- a/Master/texmf-dist/tex/context/base/regi-ini.lua
+++ b/Master/texmf-dist/tex/context/base/regi-ini.lua
@@ -12,11 +12,13 @@ if not modules then modules = { } end modules ['regi-ini'] = {
runtime.</p>
--ldx]]--
-local utfchar = utf.char
+local utfchar, utfgsub = utf.char, utf.gsub
local char, gsub, format = string.char, string.gsub, string.format
local next = next
local insert, remove = table.insert, table.remove
+
+local allocate = utilities.storage.allocate
local sequencers = utilities.sequencers
local textlineactions = resolvers.openers.helpers.textlineactions
local setmetatableindex = table.setmetatableindex
@@ -33,10 +35,15 @@ local report_translating = logs.reporter("regimes","translating")
regimes = regimes or { }
local regimes = regimes
-local mapping = {
+local mapping = allocate {
utf = false
}
+local backmapping = allocate {
+}
+
+-- regimes.mapping = mapping
+
local synonyms = { -- backward compatibility list
["windows-1250"] = "cp1250",
@@ -109,7 +116,17 @@ local function loadregime(mapping,regime)
return vector
end
-setmetatableindex(mapping, loadregime)
+local function loadreverse(t,k)
+ local t = { }
+ for k, v in next, mapping[k] do
+ t[v] = k
+ end
+ backmapping[k] = t
+ return t
+end
+
+setmetatableindex(mapping, loadregime)
+setmetatableindex(backmapping, loadreverse)
local function translate(line,regime)
if line and #line > 0 then
@@ -121,6 +138,19 @@ local function translate(line,regime)
return line
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
+end
+
local function disable()
currentregime = "utf"
sequencers.disableaction(textlineactions,"regimes.process")
@@ -136,6 +166,7 @@ local function enable(regime)
end
end
+regimes.toregime = toregime
regimes.translate = translate
regimes.enable = enable
regimes.disable = disable
@@ -145,8 +176,8 @@ regimes.disable = disable
local level = 0
-function regimes.process(str)
- if level == 0 then
+function regimes.process(str,filename,currentline,noflines,coding)
+ if level == 0 and coding ~= "utf-8" then
str = translate(str,currentregime)
if trace_translating then
report_translating("utf: %s",str)
@@ -213,6 +244,8 @@ end
-- return regime and synonyms[regime] or regime or currentregime
-- end
--
+-- commands.setregimesynonym = regimes.setsynonym
+--
-- function commands.trueregimename(regime)
-- context(regimes.truename(regime))
-- end