summaryrefslogtreecommitdiff
path: root/tex/context/base/l-table.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/l-table.lua')
-rw-r--r--tex/context/base/l-table.lua43
1 files changed, 33 insertions, 10 deletions
diff --git a/tex/context/base/l-table.lua b/tex/context/base/l-table.lua
index 23477c655..c3ef364a5 100644
--- a/tex/context/base/l-table.lua
+++ b/tex/context/base/l-table.lua
@@ -126,7 +126,7 @@ end
table.sortedkeys = sortedkeys
table.sortedhashkeys = sortedhashkeys
-function table.sortedhash(t)
+local function sortedhash(t)
local s = sortedhashkeys(t) -- maybe just sortedkeys
local n = 0
local function kv(s)
@@ -137,7 +137,8 @@ function table.sortedhash(t)
return kv, s
end
-table.sortedpairs = table.sortedhash
+table.sortedhash = sortedhash
+table.sortedpairs = sortedhash
function table.append(t, list)
for _,v in next, list do
@@ -832,12 +833,26 @@ function table.count(t)
return n
end
-function table.swapped(t)
- local s = { }
+function table.swapped(t,s)
+ local n = { }
+ if s then
+--~ for i=1,#s do
+--~ n[i] = s[i]
+--~ end
+ for k, v in next, s do
+ n[k] = v
+ end
+ end
+--~ for i=1,#t do
+--~ local ti = t[i] -- don't ask but t[i] can be nil
+--~ if ti then
+--~ n[ti] = i
+--~ end
+--~ end
for k, v in next, t do
- s[v] = k
+ n[v] = k
end
- return s
+ return n
end
--~ function table.are_equal(a,b)
@@ -860,7 +875,7 @@ function table.hexed(t,seperator)
return concat(tt,seperator or " ")
end
-function table.reverse_hash(h)
+function table.reverse_hash(h) -- needs another name
local r = { }
for k,v in next, h do
r[v] = lower(gsub(k," ",""))
@@ -908,10 +923,18 @@ function table.insert_after_value(t,value,extra)
insert(t,#t+1,extra)
end
-function table.sequenced(t,sep)
+function table.sequenced(t,sep,simple) -- hash only
local s = { }
- for k, v in next, t do -- indexed?
- s[#s+1] = k .. "=" .. tostring(v)
+ for k, v in sortedhash(t) do
+ if simple then
+ if v == true then
+ s[#s+1] = k
+ elseif v and v~= "" then
+ s[#s+1] = k .. "=" .. tostring(v)
+ end
+ else
+ s[#s+1] = k .. "=" .. tostring(v)
+ end
end
return concat(s, sep or " | ")
end