Module:no-diacritics

From Wiktionary, the free dictionary
Jump to navigation Jump to search

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

local export = {}

local acute_or_grave = "[" .. mw.ustring.char(0x301) .. mw.ustring.char(0x300) .. "]"

local accentedLetters = 'áàéèóò'

-- Decompose, remove acutes and graves, return first return value.
-- Beware: this decomposes Å to A + ◌̊.
function export.removeAccents(term)
	return term:find("[\128-\255]") and mw.ustring.gsub(mw.ustring.toNFD(term), acute_or_grave, "")
		or term
end

function export.hasAccents(term) 
	regex = '[' .. accentedLetters .. ']'
	return mw.ustring.match(term, regex) ~= nil
end

return export