Module:string/linesub

Hello, you have come here looking for the meaning of the word Module:string/linesub. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:string/linesub, but we will also tell you about its etymology, its characteristics and you will know how to say Module:string/linesub in singular and plural. Everything you need to know about the word Module:string/linesub you have here. The definition of the word Module:string/linesub will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:string/linesub, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local index_module = "Module:index"
local string_linelen_module = "Module:string/linelen"

local find = string.find
local require = require
local sub = string.sub

local function index_range(...)
	index_range = require(index_module).range
	return index_range(...)
end

local function linelen(...)
	linelen = require(string_linelen_module)
	return linelen(...)
end

return function(str, i, j)
	i, j = index_range(str, i, j, linelen)
	if j and j < i then
		return ""
	end
	local first, pos1, pos2, newline, pattern, plain = 1
	if not find(str, "\r", nil, true) then
		pattern, plain = "\n", true
	elseif not find(str, "\n", nil, true) then
		pattern, plain = "\r", true
	else
		pattern = "(\n?)"
	end
	for _ = 1, i - 1 do
		pos1, pos2, newline = find(str, pattern, first, plain)
		if pos1 == nil then
			return ""
		end
		first = newline == "\n\n" and pos2 or pos2 + 1
	end
	if j == nil then
		return sub(str, first)
	end
	local last = first
	for _ = i, j do
		pos1, pos2, newline = find(str, pattern, last, plain)
		if pos1 == nil then
			return sub(str, first)
		end
		last = newline == "\n\n" and pos2 or pos2 + 1
	end
	last = pos1 - 1
	return sub(str, first, last)
end