summaryrefslogtreecommitdiff
path: root/tex/context/base/l-aux.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/l-aux.lua')
-rw-r--r--tex/context/base/l-aux.lua68
1 files changed, 66 insertions, 2 deletions
diff --git a/tex/context/base/l-aux.lua b/tex/context/base/l-aux.lua
index aeea79173..28d4f88b2 100644
--- a/tex/context/base/l-aux.lua
+++ b/tex/context/base/l-aux.lua
@@ -163,14 +163,24 @@ function aux.array_to_string(a,separator)
end
end
-function aux.settings_to_set(str,t)
+function aux.settings_to_set(str,t) -- tohash?
t = t or { }
- for s in gmatch(str,"%s*([^,]+)") do
+ for s in gmatch(str,"%s*([^, ]+)") do -- space added
t[s] = true
end
return t
end
+function aux.simple_hash_to_string(h, separator)
+ local t = { }
+ for k, v in table.sortedhash(h) do
+ if v then
+ t[#t+1] = k
+ end
+ end
+ return concat(t,separator or ",")
+end
+
local value = lbrace * lpeg.C((nobrace + nested)^0) * rbrace
local pattern = lpeg.Ct((space + value)^0)
@@ -255,3 +265,57 @@ end
--~ end
--~ return reminder, cache
--~ end
+
+function aux.formatcolumns(result,between)
+ if result and #result > 0 then
+ between = between or " "
+ local widths, numbers = { }, { }
+ local first = result[1]
+ local n = #first
+ for i=1,n do
+ widths[i] = 0
+ end
+ for i=1,#result do
+ local r = result[i]
+ for j=1,n do
+ local rj = r[j]
+ local tj = type(rj)
+ if tj == "number" then
+ numbers[j] = true
+ end
+ if tj ~= "string" then
+ rj = tostring(rj)
+ r[j] = rj
+ end
+ local w = #rj
+ if w > widths[j] then
+ widths[j] = w
+ end
+ end
+ end
+ for i=1,n do
+ local w = widths[i]
+ if numbers[i] then
+ if w > 80 then
+ widths[i] = "%s" .. between
+ else
+ widths[i] = "%0" .. w .. "i" .. between
+ end
+ else
+ if w > 80 then
+ widths[i] = "%s" .. between
+ elseif w > 0 then
+ widths[i] = "%-" .. w .. "s" .. between
+ else
+ widths[i] = "%s"
+ end
+ end
+ end
+ local template = string.strip(concat(widths))
+ for i=1,#result do
+ local str = format(template,unpack(result[i]))
+ result[i] = string.strip(str)
+ end
+ end
+ return result
+end