Pergi ke kandungan

Modul:string/linelen

Daripada Wikikamus
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