Module:Utility

From solab
Revision as of 14:29, 16 June 2013 by imported>WikiSysop (Created page with "local p = {} local subString, lenString = mw.ustring.sub, mw.ustring.len local gm = string.gmatch function p.split(str, pat) local t = {} -- NOTE: use {n = 0} in Lua-5....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

local p = {}

local subString, lenString = mw.ustring.sub, mw.ustring.len local gm = string.gmatch

function p.split(str, pat)

  local t = {}  -- NOTE: use {n = 0} in Lua-5.0
  local fpat = "(.-)" .. pat
  local last_end = 1
  local s, e, cap = str:find(fpat, 1)
  while s do
     if s ~= 1 or cap ~= "" then

table.insert(t,cap)

     end
     last_end = e+1
     s, e, cap = str:find(fpat, last_end)
  end
  if last_end <= #str then
     cap = str:sub(last_end)
     table.insert(t, cap)
  end
  return t

end

function p.comp(x,y)

   return tostring(x[1])<tostring(y[1])

end

return p