From 788487819ccf38a8478cc2afd88e0c0b088d0ec1 Mon Sep 17 00:00:00 2001 From: Context Git Mirror Bot Date: Sat, 26 Mar 2016 13:38:18 +0100 Subject: 2016-03-26 13:07:00 --- tex/context/base/mkiv/core-con.lua | 56 ++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 18 deletions(-) (limited to 'tex/context/base/mkiv/core-con.lua') 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)) -- cgit v1.2.3