Jump to content

Module:US elections imagemap/utils: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Undid revision 1001331170 by Elliot321 (talk)
unused
Line 10: Line 10:
for word in string.gmatch(str, "[^" .. sep .. "]+") do parts[#parts+1] = p.stripspaces(word) end
for word in string.gmatch(str, "[^" .. sep .. "]+") do parts[#parts+1] = p.stripspaces(word) end
return parts
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
end



Revision as of 06:54, 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

return p