Modul:X: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 1: | Zeile 1: | ||
local p = {} --local p = {} -- p steht für Paket (engl. package) | local p = {} --local p = {} -- p steht für Paket (engl. package) | ||
function | 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 | end | ||
function p.cut( frame ) | |||
i = 2; | |||
limit = frame.args[1] | |||
text = frame.args[2] | |||
stext = split(text, " ") | |||
cuttext = stext[1] | |||
nextwo = stext[2] | |||
nextlen = string.len(nextwo) | |||
textlen = string.len(text) | |||
cuttextlen = string.len(cuttext) | |||
set = false; | |||
if(limit>=textlen)then | |||
return text.."%@%" | |||
elseif(cuttextlen>limit) then | |||
return "%@%"..text | |||
else | |||
while (cuttextlen<limit+3) do | |||
if(cuttextlen+nextlen>limit and set) then | |||
set = true | |||
cuttext = cuttext.."%@%" | |||
else | |||
cuttext = cuttext.." " | |||
end | |||
i = i + 1 | |||
cuttext = cuttext..nextwo | |||
nextwo = stext[i] | |||
nextlen = string.len(nextwo) | |||
cuttextlen = string.len(cuttext) | |||
end | |||
return cuttext | |||
end | |||
end | |||
return p | return p |
Version vom 13. Januar 2020, 19:11 Uhr
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 )
i = 2;
limit = frame.args[1]
text = frame.args[2]
stext = split(text, " ")
cuttext = stext[1]
nextwo = stext[2]
nextlen = string.len(nextwo)
textlen = string.len(text)
cuttextlen = string.len(cuttext)
set = false;
if(limit>=textlen)then
return text.."%@%"
elseif(cuttextlen>limit) then
return "%@%"..text
else
while (cuttextlen<limit+3) do
if(cuttextlen+nextlen>limit and set) then
set = true
cuttext = cuttext.."%@%"
else
cuttext = cuttext.." "
end
i = i + 1
cuttext = cuttext..nextwo
nextwo = stext[i]
nextlen = string.len(nextwo)
cuttextlen = string.len(cuttext)
end
return cuttext
end
end
return p