Module:US elections imagemap/utils
Appearance
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| Editing of this module by new or unregistered users is currently disabled. See the protection policy and protection log for more details. If you cannot edit this module and you wish to make a change, you can submit an edit request, discuss changes on the talk page, request unprotection, log in, or create an account. |
Usage
String utilities for Module:US elections imagemap.
stripspaces(str)strips spaces fromstr.split(str, sep)splitstrinto a table of strings at eachsep.
Unlike many other string utilities on Wikipedia, these are designed to be called from another Lua script easily — not to be called directly with {{#invoke}}.
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