@@ -13,16 +13,43 @@ capitalize = function(str) return string.upper(string.sub(str, 1,1)) .. string.sub(str, 2) end; - explode = function(str,delim) + beginswith = function(str,pfx) + if #str < #pfx then return false end + return string.sub(str,1,#pfx) == pfx + end; + + endswith = function(str,sfx) + if #str < #sfx then return false end + return string.sub(str,#sfx) == sfx + end; + + explode = function(str,delim,pat) -- this is messy as fuck but it works so im keeping it local i = 1 local tbl = {} + if pat == nil then pat = false end repeat local ss = string.sub(str, i) - local d = string.find(ss, delim, 1, true) or string.len(ss)+1 - tbl[#tbl+1] = string.sub(ss,1,d-1) - i = i + d + local d + if pat then + local matches = {string.match(ss, '()' .. delim .. '()')} + if #matches > 0 then + local start,stop = matches[1], matches[#matches] + d = start + i = i + stop - 1 + end + else + local dl = string.len(delim) + d = string.find(ss, delim, 1, not pat) + if d then i = i + d + dl - 1 end + end + if not d then + tbl[#tbl+1] = string.sub(ss,1,string.len(ss)) + break + else + tbl[#tbl+1] = string.sub(ss,1,d-1) + end until i > string.len(str) return tbl end;