יחידה:מונה הופעות

מתוך ויקיפדיה, האנציקלופדיה החופשית

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:מונה הופעות/תיעוד

local p = {}

function p.countlines(frame)
	local s = frame.args[1] or frame.args.text
	local _, count = s:gsub('\n', '%0') -- Count newline characters in s
	return count + 1
end

function p.count(frame)
	local ans = 0
	local c = mw.ustring.codepoint(frame.args[2], 1, 1)
	for cp in mw.ustring.gcodepoint(frame.args[1]) do
    	if cp == c then
    		ans = ans + 1
    	end
	end
	return ans
end

return p