Jump to content

Module:string/linelen

Wiktionary වෙතින්


local gmatch = string.gmatch

--[==[
Counts the number of lines in the input string, treating {"\n"}, {"\r"} and {"\r\n"} as new lines.]==]
return function(str)
	local n = 1
	for newline in gmatch(str, "([\n\r]\n?)[^\n\r]*") do
		n = n + (newline == "\n\n" and 2 or 1)
	end
	return n
end
"https://si.wiktionary.org/w/index.php?title=Module:string/linelen&oldid=222242" වෙතින් සම්ප්‍රවේශනය කෙරිණි