Module:StandardizedName

local p = {} local h = require("Module:HF")

//*** Functions for transforming pagenames of comics into desirable format ***//

--checks if pagename is comics or not function p.lua_isComics(pagename) local s = false local i = '' local j = '' i = string.find(pagename, ' Vol %d+ ') j = string.find(pagename, ' #%d+') if h.isempty(i) == false or h.isempty(j) == false then s = true end return s end

-- break down pagename of comics into parts - title, volume, issue. Also returns transformed volume number and issue number that can be used for sorting issues in categories as numbers, instead of text, including "point one" issues and "-1"/"negative" issues Also returns transformed title, with replaced characters like ":" or "/" that can be used for names of files (for example, covers) function p.lua_get_title_volume_issue(pagename) local title = '' local volume = '' local issue = '' local padded_issue = '' local padded_volume = '' local title_for_files = '' local minus = '5' local point_one = '00' local i   local j    local k

j,k = string.find(pagename, ' Vol %d+ ') if j ~= nil then title = string.sub(pagename,1,j-1) issue = string.gsub(string.sub(pagename,k+1,#pagename), '#', '') i = issue j,k,volume = string.find(pagename," Vol (%d+) ") else j,k = string.find(pagename, ' #') if h.isempty(j) == true then return '' else title = string.sub(pagename,1,j-1) issue = string.sub(pagename,k+1,#pagename) i = issue volume = '1' end end if #volume == 1 then padded_volume = '0'..volume else padded_volume = volume end -- -1 issues j = string.find(issue,"-",1,true) if h.isempty(j) == false then i = string.sub(issue,2,#issue) j = string.find(i,".",1,true) if h.isempty(j) == false then minus = 5 - #string.sub(i,1,j-1) else minus = 5 - #i end end -- point one issues j = string.find(i,".",1,true) if h.isempty(j) == false then point_one = string.sub(i,j+1,#i) i = string.sub(i,1,j-1) end padded_issue = minus..string.rep("0", 4-#i)..i..point_one -- can be used for sorting -- replaces certain characters in 'title' - used for file names title_for_files = title title_for_files = string.gsub(title_for_files,'/',' ') title_for_files = string.gsub(title_for_files,':','') title_for_files = string.gsub(title_for_files,'&#38;','&') title_for_files = string.gsub(title_for_files,'&#39;',"'")

return title, volume, issue, padded_issue, padded_volume, title_for_files end

-- removes "The " from the start of pagename function p.lua_remove_the(pagename) if h.isempty(pagename) == false and string.lower( string.sub(pagename, 1, 4) ) == 'the ' then pagename = string.sub(pagename, 5, #pagename) end return pagename end function p.remove_the(frame) return p.lua_remove_the(frame.args[1]) end

-- automatic standardization of comic names function p.lua_standardized_comics_name(pagename) title, volume, issue = p.lua_get_title_volume_issue(pagename) volume = ' Vol '..volume..' '

return title..volume..issue end function p.standardized_comics_name(frame) return p.lua_standardized_comics_name(frame.args[1]) end

-- returns comics name transformed into format for sorting it as numbers, instead of text function p.lua_comics_name_for_sorting(pagename) title, volume, issue, padded_issue, padded_volume = p.lua_get_title_volume_issue(pagename) volume = ' Vol '..padded_volume..' ' return p.lua_remove_the(title)..volume..padded_issue end function p.comics_name_for_sorting(frame) return p.lua_comics_name_for_sorting(frame.args[1]) end

return p