Zum Inhalt springen

Modul:JensbestString

aus Wikipedia, der freien Enzyklopädie

Die Dokumentation für dieses Modul kann unter Modul:JensbestString/Doku erstellt werden

local p = {}

function p.sub(frame)
	local args = frame.args
	local s = args[1] or ""
	local i = tonumber(args[2])
	local j = tonumber(args[3])

	if not i then
		return ""
	end

	local len = mw.ustring.len(s)

	if i < 0 then
		i = len + i + 1
	end

	if not j then
		j = i
	elseif j < 0 then
		j = len + j + 1
	end

	if i < 1 then
		i = 1
	end

	if j > len then
		j = len
	end

	if j < i then
		return ""
	end

	return mw.ustring.sub(s, i, j)
end

return p