Moduł:Brudnopis/BartekChom/test

Z Wikipedii, wolnej encyklopedii

Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Brudnopis/BartekChom/test/opis

local test = {}
 
function test.a( frame )
	local list = "<pre>"
	for k,v in pairs(frame.args) do
	   list = list .. k .. " = " .. v .. "\n"
	end
    return list .. "</pre>"
end

function test.IPA( frame )
	local arg = frame.args[1]

	if not arg  then
		-- missing arguments
		return nil
	end
		
	if #arg == 0 then
		-- empty argument
		return nil
	end
		
	if not mw.ustring.isutf8(arg) then
		-- invalid input is left as is
		return arg
	end
	
	--data
	local ipadata = mw.loadData( 'Moduł:IPA/data' )
	local combining = "̴̵̶̡̢̧̨̛̖̗̘̙̜̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̱̹̺̻̼͇͈͉͍͎͓͔͕͖͙͚̀́̂̃̄̅̆̇̈̉̊̋̌̍̎̏̐̑̒̓̔̽̀́͂̓̈́͆͊͋͌͐͑͒͗᷄᷅᷆᷇᷈᷉̕̚͘ͅ"
	local joining = "͡"

	--merging groups
	local parts = {}
	local joined = false
	local current = ""
	for c0 in mw.ustring.gcodepoint( arg ) do
		local c = mw.ustring.char(c0)
		if mw.ustring.match(joining, c) then
			current = current .. c
			joined = true
		elseif mw.ustring.match(combining, c) or joined then
			current = current .. c
			joined = false
		else
			if current ~= "" then
				table.insert(parts, current)
			end
			current = c
		end
	end
	
	local i = 0
	local count = #parts
	local result = ""
	while i < count do
		part = nil
		if i+1 < count then
			t = ipadata[parts[i] .. parts[i+1]]
			if t then
				if t.see then
					t = ipadata[t.see]
				end
				part = parts[i] .. parts[i+1]

				i = i+2
			end
		end

		if not part then
			t = ipadata[parts[i]]
			if t then
				if t.see then
					t = ipadata[t.see]
				end
			else
				t = ipadata[""]
			end
			
			i = i+1
		end

		result = result .. "[[" .. t.link .. "|" .. part .. "]]"
	end
	
	return result
end

return test