Module:Auto sort

From Wikisource
Jump to navigation Jump to search

--[=[
Simple functions for constructing sort keys
]=]

local p = {} --p stands for package

--[=[
This function is the usual function for titles

Be default, it strips english articles: A, An, The and puts them at the end of the string
]=]
function p.normalTitles( title )
	
	local articles = { 'A', 'An', 'The' }
	
	for _, article in pairs( articles ) do
		-- starts with the article
		if mw.ustring.find( title, article .. ' ', 1 ) == 1 then
			title = mw.ustring.sub( title, mw.ustring.len( article ) + 2 ) .. ', ' .. article
			break
		end
	end
	
	return title
end

return p