Modul:Hilfsfunktionen: Unterschied zwischen den Versionen

Aus GaretienWiki
Zur Navigation springen Zur Suche springen
VolkoV (D | B)
(Die Seite wurde neu angelegt: „ function robusttrim(s) if s==nil then return '' end local p=mw.ustring.gsub(s,'%[%[SMW::on%]%]','') p=mw.ustring.gsub(p,'%[%[SMW::off%]%]','') return…“)
 
VolkoV (D | B)
Zeile 1: Zeile 1:
function robusttrim(s)
+
-- Macht einen Trim in Kombination mit dem Entfernen der SMW-Tags
if s==nil then return '' end
+
function robusttrim(s)
local p=mw.ustring.gsub(s,'%[%[SMW::on%]%]','')
+
if s==nil then return '' end
p=mw.ustring.gsub(p,'%[%[SMW::off%]%]','')
+
local p=mw.ustring.gsub(s,'%[%[SMW::on%]%]','')
return mw.text.trim(p)
+
p=mw.ustring.gsub(p,'%[%[SMW::off%]%]','')
end
+
return mw.text.trim(p)
+
end
function split(inputstr,sep)
+
 
if sep==nil then sep="%s" end
+
-- Splittet einen String in einen Array anhand eines Separators
local t={}
+
function split(inputstr,sep)
local i=1
+
if sep==nil then sep="%s" end
for str in mw.ustring.gmatch(inputstr,"([^"..sep.."]+)") do
+
local t={}
t[i]=str
+
local i=1
i=i+1
+
for str in mw.ustring.gmatch(inputstr,"([^"..sep.."]+)") do
end
+
t[i]=str
if i==1 then t[1]=inputstr end
+
i=i+1
return t
 
 
end
 
end
 +
if i==1 then t[1]=inputstr end
 +
return t
 +
end

Version vom 18. Mai 2021, 16:45 Uhr

Dokumentation und Testfälle unter Modul:Hilfsfunktionen/Doku.
-- Macht einen Trim in Kombination mit dem Entfernen der SMW-Tags
function robusttrim(s)
	if s==nil then return '' end
	local p=mw.ustring.gsub(s,'%[%[SMW::on%]%]','')
	p=mw.ustring.gsub(p,'%[%[SMW::off%]%]','')
	return mw.text.trim(p)
end

-- Splittet einen String in einen Array anhand eines Separators
function split(inputstr,sep)
	if sep==nil then sep="%s" end
	local t={}
	local i=1
	for str in mw.ustring.gmatch(inputstr,"([^"..sep.."]+)") do
		t[i]=str
		i=i+1
	end
	if i==1 then t[1]=inputstr end
	return t
end