Module:palindromes

Hello, you have come here looking for the meaning of the word Module:palindromes. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:palindromes, but we will also tell you about its etymology, its characteristics and you will know how to say Module:palindromes in singular and plural. Everything you need to know about the word Module:palindromes you have here. The definition of the word Module:palindromes will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:palindromes, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

local data = mw.loadData("Module:palindromes/data")

local function ignoreCharacters(term, lang, sc, langdata)
	term = mw.ustring.lower(term)
	term = mw.ustring.gsub(term, "", "")
	
	-- Language-specific substitutions

	-- Ignore entire scripts (e.g. romaji in Japanese)
	if langdata.ignore then
		sc_name = sc and sc:getCode() or lang:findBestScript(term):getCode()
		for _, script in ipairs(langdata.ignore) do
			if script == sc_name then
				return ""
			end
		end
	end
	
	for i, from in ipairs(langdata.from or {}) do
		term = mw.ustring.gsub(term, from, langdata.to or "")
	end
	
	return term
end

function export.is_palindrome(term, lang, sc)
	local langdata = data or data or {}

	-- Affixes aren't palindromes
	if mw.ustring.find(term, "^%-") or mw.ustring.find(term, "%-$") then
		return false
	end
	
	-- Remove punctuation and casing
	term = ignoreCharacters(term, lang, sc, langdata)
	local len = mw.ustring.len(term)
	
	if langdata.allow_repeated_char then
		-- Ignore single-character terms
		if len < 2 then
			return false
		end
	else
		-- Ignore terms that consist of just one character repeated
		-- This also excludes terms consisting of fewer than 3 characters
		if term == mw.ustring.rep(mw.ustring.sub(term, 1, 1), len) then
			return false
		end
	end
	
	local charlist = {}
	
	for c in mw.ustring.gmatch(term, ".") do
		table.insert(charlist, c)
	end
	
	for i = 1, math.floor(len / 2) do
        if charlist ~= charlist then
        	return false
        end
    end
    
    return true
end

return export