Jump to content

Module:US elections imagemap/utils: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
No edit summary
Tag: Reverted
Line 17: Line 17:
end
end
return t1
return t1
end

function p.getTableKeys(tab)
local keyset = {}
for k,v in pairs(tab) do
keyset[#keyset + 1] = k
end
return keyset
end
end



Revision as of 06:29, 19 January 2021

local p = {}

function p.stripspaces(str)
	return str:gsub("^%s*(.-)%s*$", "%1") -- trim spaces
end

function p.split(str, sep) -- split string by separator and return table
  sep = sep or "%s"
  local parts = {}
  for word in string.gmatch(str, "[^" .. sep .. "]+") do parts[#parts+1] = p.stripspaces(word) end
  return parts
end

function p.listmerge(t1, t2) -- only works on tables that are lists, not dictionaries
	for i, j in ipairs(t2) do
		table.insert(t1, j)
	end
	return t1
end

function p.getTableKeys(tab)
  local keyset = {}
  for k,v in pairs(tab) do
    keyset[#keyset + 1] = k
  end
  return keyset
end

return p