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]

--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","Role"} table = {input[1],input[2],input[3],input[4],input[6],input[7],input[8]} --mw.logObject("table: ") --mw.logObject(table) emptyVal = "" missing = 0 for i,val in ipairs(table) do       --mw.logObject(legend[i].." = "..val) if (val == "empty") then fieldPlural = "Field" missing = missing + 1 if (missing > 1) then fieldPlural = "Fields" end mw.logObject("! "..legend[i].." empty") emptyVal = emptyVal..legend[i].." | " --mw.logObject(emptyVal) error = " "..fieldPlural.." | "..emptyVal.."can not be empty. See Help:Guidelines. " end if (val:find("?[^%w]+%?+$")) then mw.logObject(legend[i].." is a question mark field field") if (error) then mw.logObject("test") error = error .. ""           else error = "" end end end --check if valid type combination

valid = {} valid["Alien"]        = "empty" valid["Construct"]    = "Celestial~Doll~Familiar~Homunculus~Machine~Object~Organic~Program" valid["Demonic"]      = "empty" 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~Shinigami~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