सामग्री पर जाएँ

मॉड्यूल:ar-stripdiacritics

विक्षनरी से

package.lua में पंक्ति 80 पर लुआ त्रुटि: module 'Module:languages/byStripDiacriticsModule' not found।

local m_str_utils = require("Module:string utilities")

local find = m_str_utils.find
local gsub = m_str_utils.gsub
local U = m_str_utils.char

local taTwiil = U(0x640)
local waSla = U(0x671)
-- diacritics ordinarily removed by entry_name replacements
local Arabic_diacritics = U(
	0x64B, -- fathatan
	0x64C, -- dammatan
	0x64D, -- kasratan
	0x64E, -- fatha
	0x64F, -- damma
	0x650, -- kasra
	0x651, -- shadda
	0x652, -- sukun
	0x656, -- subscript alif
	0x657, -- inverted damma
	0x670, -- superscript (dagger) alif
	0x6DF, -- sifr mustadir
	0x6E0, -- sifr mustatil
	0x6E1, -- variant sukun
	0x8F0, -- open fathatan
	0x8F1, -- open dammatan
	0x8F2  -- open kasratan
)

-- replace alif waṣl with alif
-- remove tatweel and diacritics
local replacements = {
	from = {U(0x0671), "[" .. taTwiil .. Arabic_diacritics .. "]"},
	to   = {U(0x0627)},
}

local export = {}

function export.stripDiacritics(text, lang, sc)
	if text == waSla or find(text, "^" .. taTwiil .. "?[" .. Arabic_diacritics .. "]" .. "$") then
		return text
	end
	
	for i, from in ipairs(replacements.from) do
		local to = replacements.to[i] or ""
		text = gsub(text, from, to)
	end
	
	return text
end

return export