• Welcome to Touhou Wiki!
  • Registering is temporarily disabled. Check in our Discord server to request an account and for assistance of any kind.

Module:MW.text

From Touhou Wiki
Revision as of 19:14, 8 August 2013 by DennouNeko (talk | contribs) (Protected "Module:MW.text": High traffic page: core Lua module ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
-- This is just a helper library that implements some missing features from current Scribunto release

local common = require("Module:Common")

text = {}

function text.trim(val)
  return tostring(val):gsub("^%s*(.-)%s*$", "%1")
end

function text.split(str, sep, lit)
  local pos = 1
  local t = {}
  if not common.isset(sep) or not common.isset(str) then return t end
    for s, e in function() return string.find(str, sep, pos) end do
    t[#t+1] = text.trim(string.sub(str, pos, s-1))
    pos = e+1
  end
  t[#t+1] = text.trim(string.sub(str, pos))
  return t
end

return text