summaryrefslogtreecommitdiff
path: root/tex/context/base/l-aux.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2010-08-14 15:56:20 +0300
committerMarius <mariausol@gmail.com>2010-08-14 15:56:20 +0300
commitb469b8ec1b494ab72cd462bfc539ce01440e6aaf (patch)
tree3a9c3fb8433c5f75020fef1d531bedb7c948f66c /tex/context/base/l-aux.lua
parent39e30629c15ae4a899532d84c4abea127f2847a6 (diff)
downloadcontext-b469b8ec1b494ab72cd462bfc539ce01440e6aaf.tar.gz
beta 2010.08.10 17:14
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