Module:Utils

local libraryUtil = require( 'libraryUtil' ) local p = {}

-- String interpolation with named variables. function p.interp(str, tab) assert(str and table, 'interp: Missing arguments') libraryUtil.checkType( 'interp', 1, str, 'string' ) libraryUtil.checkType( 'interp', 2, tab, 'table' )

return (str:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end)) end

-- Use this function instead of mw.text.split. function p.split(str, pattern) assert(str and pattern, 'split: Missing arguments') libraryUtil.checkType( 'split', 1, str, 'string' ) libraryUtil.checkType( 'split', 2, pattern, 'string' ) local i, out = 1, {} local split_start, split_end = string.find(str, pattern, i) while split_start do    out[#out + 1] = string.sub(str, i, split_start - 1) i = split_end + 1 split_start, split_end = string.find(str, pattern, i) end out[#out + 1] = string.sub(str, i) return out end

return p