Module:Validate

--if anyone ever tries to read this code, I'm sorry.

--require('Module:StrManip')

local p = {}

function strSplit(str,sep) local t = {} for k, v in string.gmatch(str, sep.."(.-)"..sep) do       table.insert(t, k)    end return t end

function p.validate local str = mw.getCurrentFrame.args[1] --comma separated list of strings |||| !! with "empty" as empty value

--image,name,kana,type,subtype,series,medium

--local str = "¦¦image.png¦¦¦¦¦¦¦¦ユイ¦¦¦¦Undead¦¦¦¦asdfas¦¦¦¦the last module on this little wiki¦¦¦¦¦¦¦¦" str = str:gsub("¦¦¦¦","¦¦empty¦¦"):gsub("¦¦¦¦","¦¦empty¦¦"):gsub("¦¦¦¦","¦¦empty¦¦"):gsub("¦¦¦¦","¦¦empty¦¦"):gsub("¦¦¦¦","¦¦empty¦¦"):gsub("¦¦¦¦","¦¦empty¦¦"):gsub("¦¦¦¦","¦¦empty¦¦"):gsub("ユ","YU") mw.logObject("str: "..str) error = mw.logObject(str) local input = strSplit(str,"¦¦") mw.logObject("split input: ") mw.logObject(input)

--check for empty values legend = {"Image","Name","Kana","Type","Series","Medium"} table = {input[1],input[2],input[3],input[4],input[6],input[7]} mw.logObject("table: ") mw.logObject(table) emptyVal = "" for i,val in ipairs(table) do       --mw.logObject(legend[i].." = "..val) if (val == "empty") then mw.logObject("! "..legend[i].." empty") emptyVal = emptyVal..legend[i].." | " --mw.logObject(emptyVal) error = " Fields | "..emptyVal.."need to be filled out. See Help:Guidelines. " end end --check if valid type combination

valid = {} valid["Alien"]        = "empty" valid["Construct"]    = "Celestial~Doll~Familiar~Homunculus~Machine~Object~Organic~Program" valid["Divine"]       = "Angel~Demi Goddess~Deity" valid["Grimoire"]     = "empty" valid["Heroic Spirit"] = "Servant" valid["Magical"]      = "Magical Girl~Witch~Wizard" valid["Mythological"] = "Dragon~Dwarf~Elf~Fairy~Halfling~Kitsune~Medusa~Oni~Shikigami~Spirit~Youkai" valid["Scientific"]   = "Drug~Genetic" valid["Natural"]      = "empty" valid["Transcendent"] = "empty" valid["Undead"]       = "Ghost~Vampire~Zombie" valid["Unknown"]      = "empty"

--mw.logObject(valid["Construct"])

types = {input[4],input[5]} mw.logObject("Types") mw.logObject(types) if (valid[types[1]]) then mw.logObject(types[1].." is a valid type") if not (valid[types[1]]:find(types[2])) then if (error) then mw.logObject(types[2].." not a subtype of "..types[1]) error = error .. " " .. types[2].." is not a Sub Type of "..types[1] .." " else error = " " .. types[2].." is not a Sub Type of "..types[1] .." " end else mw.logObject(types[2].." is a Sub Type of "..types[1]) end else if (error) then error = error .. " " .. types[1].." is not a valid Type. " else error = " " .. types[1].." is not a valid Type. " end end mw.logObject(error) return error end

return p