Modul:X

Aus How to be a Hero
Wechseln zu: Navigation, Suche

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

local p = {} --local p = {} -- p steht für Paket (engl. package)

function split (inputstr, sep)
        if sep == nil then
                sep = "%s"
        end
        local t={}
        for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
                table.insert(t, str)
        end
        return t
end

function p.cut( frame )
	
	realtext = frame.args[2] --fiick dich halli
	realtext = removespaceinlink(realtext)
	srealtext = split(realtext, " ") --fiick|dich|halli(list)
	i = 2; --2
	limit = tonumber(frame.args[1]) --11
	text = display(realtext) --fiick dich halli
	stext = split(text, " ") --fiick|dich|halli(list)
	
	if(table.getn(stext)==1) then
		if(string.len(stext[1])>limit) then
			return "%@%"..text
		else
			return text.."%@%"
		end
	end
	
	cuttext = stext[1] --fiick
	realcuttext = srealtext[1] --fiick
	testtext = "1: "..realcuttext.."<br />"
	nextwo = stext[2] --dich
	realnextwo = srealtext[2] --dich
	
	nextlen = string.len(nextwo)--4
	textlen = string.len(text)--16
	cuttextlen = string.len(cuttext)--5
	
	set = true;
	
	if(limit>=textlen)then --11>=16
		return realtext.."%@%"
	
	elseif(cuttextlen>limit) then--5>11
		return "%@%"..realtext
		
	

	else
		a = "h"..realnextwo
		
		while (cuttextlen+nextlen+1<=textlen-22) do --5+4+1<=16+2(10<=18)|12
			
			if(cuttextlen+nextlen+1>limit and set) then --5+4+1>11(10>11)|
				set = false
				cuttext = cuttext.."%@%" --
				realcuttext = realcuttext.."%@%" --
				
			else
				cuttext = cuttext.." " --"fiick "
				realcuttext = realcuttext.." " --"fiick "
				
			end
			testtext = testtext..tostring(i)..": "..realcuttext.."<br />"
			i = i + 1 --3
			
			cuttext = cuttext..nextwo -- fiick dich
			realcuttext = realcuttext..realnextwo -- fiick dich
			
			nextwo = stext[i]-- halli
			realnextwo = srealtext[i]-- halli
			
			if (nextwo ~= nil) then
				nextlen = string.len(nextwo) -- 5
			end
			cuttextlen = string.len(cuttext) -- 12
			
			
		end
		if (realnextwo ~= nil) then
			realcuttext = realcuttext.." "..realnextwo
		end
	end
	return realcuttext
end


function cut( limit, realtext )
	realtext = removespaceinlink(realtext)
	srealtext = split(realtext, " ") --fiick|dich|halli(list)
	i = 2; --2
	text = display(realtext) --fiick dich halli
	stext = split(text, " ") --fiick|dich|halli(list)
	
	if(table.getn(stext)==1) then
		if(string.len(stext[1])>limit) then
			return "%@%"..text
		else
			return text.."%@%"
		end
	end
	
	cuttext = stext[1] --fiick
	realcuttext = srealtext[1] --fiick
	
	nextwo = stext[2] --dich
	realnextwo = srealtext[2] --dich
	
	nextlen = string.len(nextwo)--4
	textlen = string.len(text)--16
	cuttextlen = string.len(cuttext)--5
	
	set = true;
	
	if(limit>=textlen)then --11>=16
		return realtext.."%@%"
	
	elseif(cuttextlen>limit) then--5>11
		return "%@%"..realtext
		
	

	else
	
		while (cuttextlen+nextlen+1<=textlen+2) do --5+4+1<=16+2(10<=18)|12
			
			if(cuttextlen+nextlen+1>limit and set) then --5+4+1>11(10>11)|
				set = false
				cuttext = cuttext.."%@%" --
				realcuttext = realcuttext.."%@%" --
				
			else
				cuttext = cuttext.." " --"fiick "
				realcuttext = realcuttext.." " --"fiick "
				
			end
			
			i = i + 1 --3
			
			cuttext = cuttext..nextwo -- fiick dich
			realcuttext = realcuttext..realnextwo -- fiick dich
			
			nextwo = stext[i]-- halli
			realnextwo = srealtext[i]-- halli
			
			if (nextwo ~= nil) then
				nextlen = string.len(nextwo) -- 5
			end
			cuttextlen = string.len(cuttext) -- 12
			
			
		end
		if (realnextwo ~= nil) then
			realcuttext = realcuttext.." "..realnextwo
		end
	end
	return realcuttext
end


function p.cutblock ( frame )
	text = frame.args[3]
	width = tonumber(frame.args[2])
	height = tonumber(frame.args[1])
	block = ""
	textlen = string.len(text)
	tempsplit = {}
	
	
	while (height>0 and textlen>=width) do
		tempsplit = split(cut(width, text), "%%%@%%")
		block = block..tempsplit[1].." "
		text = tempsplit[2]
		height = height-1
		textlen = string.len(text)
	end
	if (height>0) then
		block = block.." "..text
		text = ""
	end
	
	
	return block.."%@%"..text


end

function p.display ( frame )
	text = frame.args[1]
	text = text:gsub("'", "")
	i=1
	auf = {}
	zu = {}
	currentauf = string.find(text, "%[%[")
	while (currentauf ~= nil) do
		auf[i] = currentauf;
		if (string.find(string.sub(text,currentauf+2), "%[%[")~=nil)then
			currentauf = currentauf+1+string.find(string.sub(text,currentauf+2), "%[%[")
		else
			currentauf = nil
		end
		
		i=i+1
	end
	
	i=1
	currentzu = string.find(text, "%|")
	while (currentzu ~= nil) do
		zu[i] = currentzu;
		if (string.find(string.sub(text,currentzu+2), "%|")~=nil)then
			currentzu = currentzu+1+string.find(string.sub(text,currentzu+2), "%|")
		else
			currentzu = nil
		end
		i=i+1
	end
	offset = 0
	
	if(table.getn(auf) == table.getn(zu))then
		i=1
		while (table.getn(auf)>=i) do
			anfang = auf[i]
			ende = zu[i]
			text = string.sub(text,1,anfang-offset)..string.sub(text,ende+1-offset,string.len(text))
			offset = offset+string.len(string.sub(text,anfang+1,ende))
			i=i+1
		end
	end
	text = text:gsub("%[", "")
	text = text:gsub("%|", "")
	text = text:gsub("%]", "")

	return text
end

function display ( text )
	text = text:gsub("'", "")
	i=1
	auf = {}
	zu = {}
	currentauf = string.find(text, "%[%[")
	while (currentauf ~= nil) do
		auf[i] = currentauf;
		if (string.find(string.sub(text,currentauf+2), "%[%[")~=nil)then
			currentauf = currentauf+1+string.find(string.sub(text,currentauf+2), "%[%[")
		else
			currentauf = nil
		end
		
		i=i+1
	end
	
	i=1
	currentzu = string.find(text, "%|")
	while (currentzu ~= nil) do
		zu[i] = currentzu;
		if (string.find(string.sub(text,currentzu+2), "%|")~=nil)then
			currentzu = currentzu+1+string.find(string.sub(text,currentzu+2), "%|")
		else
			currentzu = nil
		end
		i=i+1
	end
	offset = 0
	
	if(table.getn(auf) == table.getn(zu))then
		i=1
		while (table.getn(auf)>=i) do
			anfang = auf[i]
			ende = zu[i]
			text = string.sub(text,1,anfang-offset)..string.sub(text,ende+1-offset,string.len(text))
			offset = offset+string.len(string.sub(text,anfang+1,ende))
			i=i+1
		end
	end
	text = text:gsub("%[", "")
	text = text:gsub("%|", "")
	text = text:gsub("%]", "")

	return text
end

function removespaceinlink(text)
	i=1
	auf = {}
	zu = {}
	currentauf = string.find(text, "%[%[")
	while (currentauf ~= nil) do
		auf[i] = currentauf;
		if (string.find(string.sub(text,currentauf+2), "%[%[")~=nil)then
			currentauf = currentauf+1+string.find(string.sub(text,currentauf+2), "%[%[")
		else
			currentauf = nil
		end
		
		i=i+1
	end
	
	i=1
	currentzu = string.find(text, "%]%]")
	while (currentzu ~= nil) do
		zu[i] = currentzu;
		if (string.find(string.sub(text,currentzu+2), "%]%]")~=nil)then
			currentzu = currentzu+1+string.find(string.sub(text,currentzu+2), "%]%]")
		else
			currentzu = nil
		end
		i=i+1
	end
	if(table.getn(auf) == table.getn(zu))then
		i=1
		while (table.getn(auf)>=i) do
			anfang = auf[i]
			ende = zu[i]
			text = string.sub(text,1,anfang-1)..string.gsub(string.sub(text,anfang,ende)," ","§")..string.sub(text,ende+1,string.len(text))

			i=i+1
		end
	end
	
	return text
end

function p.removespaceinlink(frame)
	text = frame.args[1]
	i=1
	auf = {}
	zu = {}
	currentauf = string.find(text, "%[%[")
	while (currentauf ~= nil) do
		auf[i] = currentauf;
		if (string.find(string.sub(text,currentauf+2), "%[%[")~=nil)then
			currentauf = currentauf+1+string.find(string.sub(text,currentauf+2), "%[%[")
		else
			currentauf = nil
		end
		
		i=i+1
	end
	
	i=1
	currentzu = string.find(text, "%]%]")
	while (currentzu ~= nil) do
		zu[i] = currentzu;
		if (string.find(string.sub(text,currentzu+2), "%]%]")~=nil)then
			currentzu = currentzu+1+string.find(string.sub(text,currentzu+2), "%]%]")
		else
			currentzu = nil
		end
		i=i+1
	end
	if(table.getn(auf) == table.getn(zu))then
		i=1
		while (table.getn(auf)>=i) do
			anfang = auf[i]
			ende = zu[i]
			text = string.sub(text,1,anfang-1)..string.gsub(string.sub(text,anfang,ende)," ","§")..string.sub(text,ende+1,string.len(text))

			i=i+1
		end
	end
	
	return text
end






function p.size ( frame )
	text = frame.args[1]
	return textSize(text)
end





function p.size ( frame )
	text = frame.args[1]
	return textSize(text)
end

function p.findg( frame )
	text = frame.args[1]
	d,s,r = string.find(text, "g")
	return d,s,r

end






return p