Module:User:Daniel Carrero/components

local m_unsupported_titles = require("Module:unsupported titles")

local export = {}

local function link(entry) local parseUnsupportedTitle = m_unsupported_titles.parse(entry, null, true, true)

if parseUnsupportedTitle then return parseUnsupportedTitle else return "" .. entry .. "" end end

local function characters(text) local result = ""

if mw.ustring.len(text) == 0 then return nil end

local characters = mw.text.split(text, "") for _, v in pairs(characters) do result = result .. link(v) end

return result end

local function getSeparatorOffsets(text) local acceptableSeparators = "[ ,%.!/;:-%(%)%[%]%{%}]" local separatorOffsets = {}

for i=1, mw.ustring.len(text), 1 do		local currentCharacter = mw.ustring.sub(text, i, i)		if mw.ustring.find(currentCharacter, acceptableSeparators) then table.insert(separatorOffsets, i)		end end

return separatorOffsets end

local function getWordBoundaries(text, separatorOffsets) local wordBoundaries = {}

for i=1, mw.ustring.len(text), 1 do	end

for k, v in pairs(separatorOffsets) do		local currentCharacter = mw.ustring.sub(text, i, i)

local startWord = nil local endWord = nil

if separatorOffsets[k+1] then if separatorOffsets[k]+1 == separatorOffsets[k+1] then startWord = nil else startWord = v+1 end else if k == mw.ustring.len(text) then startWord = nil else startWord = v+1 end end

if separatorOffsets[k+1] then endWord = separatorOffsets[k+1]-1 else endWord = mw.ustring.len(text) end

if startWord then wordBoundaries[startWord] = endWord end end

return wordBoundaries end

local function simpleWords(text, separatorOffsets, wordBoundaries) local result = ""

for i=1, mw.ustring.len(text), 1 do		if separatorOffsets[i] then result = result .. mw.ustring.sub(text, separatorOffsets[i], separatorOffsets[i]) elseif wordBoundaries[i] then result = result .. mw.ustring.sub(text, i, wordBoundaries[i]) end end

return result end

local function wordVariations(text, separatorOffsets, wordBoundaries) local offsets = getOffsets(text) local result = ""

local englishObject = mw.language.new("en") local acceptableVariations = {englishObject:uc(entry), englishObject:ucfirst(entry), englishObject:lc(entry),} local verifiedVariations = {} local nonzeroVerifiedVariations = false

for _, v in pairs(acceptableVariations) do		if entry ~= v then local titleObject = mw.title.new(v) if titleObject.exists then local alreadyListed = false for l, w in pairs(verifiedVariations) do					if v == w then alreadyListed = true end end if alreadyListed == false then nonzeroVerifiedVariations = true table.insert(verifiedVariations, v)				end end end end

if nonzeroVerifiedVariations == true then result = "("		for k, v in pairs(verifiedVariations) do			if k > 1 then result = result .. ", " end			result = result .. link(v)		end		result = result .. ") " else result = nil end

return result

end

function export.parse(frame) local text = frame:getParent.args[1] local result = "" local separatorOffsets = getSeparatorOffsets(text) -- local wordBoundaries = getWordBoundaries(text, separatorOffsets)

-- local words = simpleWords(text, separatorOffsets, wordBoundaries) -- local variations = wordVariations(text, separatorOffsets, wordBoundaries)

result = result .. " "

return result end

return export