summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/core-con.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-03-26 13:38:18 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-03-26 13:38:18 +0100
commit788487819ccf38a8478cc2afd88e0c0b088d0ec1 (patch)
tree215addbe3b9e293c2958227e7fc8923880b2e71f /tex/context/base/mkiv/core-con.lua
parentadfe72d5a0c9d7bdc1bd7bc8faabb4d05e21d70a (diff)
downloadcontext-788487819ccf38a8478cc2afd88e0c0b088d0ec1.tar.gz
2016-03-26 13:07:00
Diffstat (limited to 'tex/context/base/mkiv/core-con.lua')
-rw-r--r--tex/context/base/mkiv/core-con.lua56
1 files changed, 38 insertions, 18 deletions
diff --git a/tex/context/base/mkiv/core-con.lua b/tex/context/base/mkiv/core-con.lua
index 53f9734dc..bfe5357a6 100644
--- a/tex/context/base/mkiv/core-con.lua
+++ b/tex/context/base/mkiv/core-con.lua
@@ -28,8 +28,10 @@ local implement = interfaces.implement
local settings_to_array = utilities.parsers.settings_to_array
local allocate = utilities.storage.allocate
+local setmetatableindex = table.setmetatableindex
local formatters = string.formatters
local variables = interfaces.variables
+local constants = interfaces.constants
converters = converters or { }
local converters = converters
@@ -609,12 +611,23 @@ function converters.define(name,set) -- ,language)
sequences[name] = settings_to_array(set)
end
+function converters.max(name)
+ local s = sequences[name]
+ return s and #s or 0
+end
+
implement {
name = "defineconversion",
actions = converters.define,
arguments = { "string", "string" }
}
+implement {
+ name = "nofconversions",
+ actions = { converters.max, context },
+ arguments = "string",
+}
+
local function convert(method,n,language)
local converter = language and converters[method..":"..language] or converters[method]
if converter then
@@ -1137,7 +1150,7 @@ local v_WEEKDAY = upper(v_weekday)
local convert = converters.convert
-local days = { -- not variables.sunday
+local days = { -- not variables
"sunday",
"monday",
"tuesday",
@@ -1147,7 +1160,7 @@ local days = { -- not variables.sunday
"saturday",
}
-local months = { -- not variables.january
+local months = { -- not variables
"january",
"february",
"march",
@@ -1162,21 +1175,28 @@ local months = { -- not variables.january
"december",
}
+local monthmnems = { -- not variables
+ -- virtual table
+}
+
+setmetatableindex(months, function(t,k) return "unknown" end)
+setmetatableindex(days, function(t,k) return "unknown" end)
+setmetatableindex(monthmnems, function(t,k) return months[k] .. ":mnem" end)
+
local function dayname(n)
- return days[n] or "unknown"
+ return days[n]
end
local function weekdayname(day,month,year)
- return days[weekday(day,month,year)] or "unknown"
+ return days[weekday(day,month,year)]
end
local function monthname(n)
- return months[n] or "unknown"
+ return months[n]
end
local function monthmnem(n)
- local m = months[n]
- return m and (m ..":mnem") or "unknown"
+ return monthmnems[n]
end
implement {
@@ -1252,19 +1272,19 @@ local function currentdate(str,currentlanguage) -- second argument false : no la
context("%02i",year % 100)
elseif tag == v_month or tag == "m" then
if currentlanguage == false then
- context(months[month] or "unknown")
+ context(months[month])
elseif mnemonic then
- context.labeltext(monthmnem(month))
+ context.labeltext(variables[monthmnems[month]])
else
- context.labeltext(monthname(month))
+ context.labeltext(variables[months[month]])
end
elseif tag == v_MONTH then
if currentlanguage == false then
- context.WORD(months[month] or "unknown")
+ context.WORD(variables[months[month]])
elseif mnemonic then
- context.LABELTEXT(monthmnem(month))
+ context.LABELTEXT(variables[monthmnems[month]])
else
- context.LABELTEXT(monthname(month))
+ context.LABELTEXT(variables[months[month]])
end
elseif tag == "mm" then
context("%02i",month)
@@ -1272,7 +1292,7 @@ local function currentdate(str,currentlanguage) -- second argument false : no la
context(month)
elseif tag == v_day or tag == "d" then
if currentlanguage == false then
- context(days[day] or "unknown")
+ context(days[day])
else
context.convertnumber(v_day,day) -- why not direct
end
@@ -1286,16 +1306,16 @@ local function currentdate(str,currentlanguage) -- second argument false : no la
elseif tag == v_weekday or tag == "w" then
local wd = weekday(day,month,year)
if currentlanguage == false then
- context(days[wd] or "unknown")
+ context(days[wd])
else
- context.labeltext(days[wd] or "unknown")
+ context.labeltext(variables[days[wd]])
end
elseif tag == v_WEEKDAY then
local wd = weekday(day,month,year)
if currentlanguage == false then
- context.WORD(days[wd] or "unknown")
+ context.WORD(days[wd])
else
- context.LABELTEXT(days[wd] or "unknown")
+ context.LABELTEXT(variables[days[wd]])
end
elseif tag == "W" then
context(weekday(day,month,year))