Modul:Common: Unterschied zwischen den Versionen

keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 16: Zeile 16:
local args = frame.args
local args = frame.args
     local title = mw.title.getCurrentTitle().text
     local title = mw.title.getCurrentTitle().text
     local tag, monat = istJahrestag(title)
     local tag, monat = p.ist_jahrestag(title)
      
      
     if tag and monat then
     if tag and monat then
Zeile 25: Zeile 25:
end
end


function istJahrestag(s)
function p.ist_jahrestag(s)
s = s or ""
s = s or ""
-- Prüfe auf ein-/zweistellige Zahl durch Punkt gefolgt, opt. Leerzeichen
-- Prüfe auf ein-/zweistellige Zahl durch Punkt gefolgt, opt. Leerzeichen
Zeile 35: Zeile 35:
     local title = mw.title.getCurrentTitle().text
     local title = mw.title.getCurrentTitle().text


     if istJahreszahl(title) then
     if p.ist_jahreszahl(title) then
         return args[1] or "true"
         return args[1] or "true"
     else
     else
Zeile 42: Zeile 42:
end
end


function istJahreszahl(s)
function p.ist_jahreszahl(s)
s = s or ""
s = s or ""
-- Prüfe auf Formate wie: 2024, -44, 44 v. Chr., 800 n. Chr.
-- Prüfe auf Formate wie: 2024, -44, 44 v. Chr., 800 n. Chr.
Zeile 60: Zeile 60:
end
end


function getMonthList()
function p.getMonthList()
-- Returns a numbered List of all monthnames
-- Returns a numbered List of all monthnames
return {
return {
Zeile 77: Zeile 77:
end
end


function getMonthnr(name)  
function p.getMonthnr(name)  
-- Returns the number of the given monthname  
-- Returns the number of the given monthname  
local months = getMonthList()
local months = getMonthList()
Zeile 91: Zeile 91:
end
end


function len(t)
function p.len(t)
     -- Überprüfe, ob es ein String ist
     -- Überprüfe, ob es ein String ist
     if type(t) == "string" then
     if type(t) == "string" then
Zeile 110: Zeile 110:
         return nil  -- Falls der Typ nicht unterstützt wird
         return nil  -- Falls der Typ nicht unterstützt wird
     end
     end
end
function contains(list, str)
-- Obsolet
for i, v in ipairs(list) do
if v == str then
return true
end
end
return false
end
end


Zeile 126: Zeile 116:
end
end


function get_key_for_value( t, value )
function p.get_key_for_value( t, value )
   for k, v in pairs(t) do
   for k, v in pairs(t) do
     if v==value then return k end
     if v==value then return k end
Zeile 133: Zeile 123:
end
end


function rtrim(s)
function p.merge_arrays(t1, t2)
-- Obsolet
-- Removes all spaces at the end of a string
return s:gsub("%s+$", "")
end
 
function ltrim(s)
-- Obsolet
-- Removes all spaces at the start of a string
return s:match("^%s*(.-)$")
end
 
function strip(s)
-- Obsolet
-- Removes all spaces at the start and at the end of a string
    return s:match("^%s*(.-)%s*$")
end
 
function merge_arrays(t1, t2)
-- merge tables that are arrays: {1,2,3} and {3,4,5}
-- merge tables that are arrays: {1,2,3} and {3,4,5}
     local result = {}
     local result = {}
Zeile 163: Zeile 135:
end
end


function merge_tables(t1, t2)
function p.merge_tables(t1, t2)
-- merge tables that are key-value: {a=1, b=2} and {c=3, d=4}
-- merge tables that are key-value: {a=1, b=2} and {c=3, d=4}
local result={}
local result={}
Zeile 173: Zeile 145:
end
end
return result
return result
end
function split(s, d)
-- Obsolet
if d == nil then d = "%s" end
local arr = {}
local n = 0
for i in string.gmatch(s, "([^" .. d .. "]+)") do
arr[n] = i
n = n + 1
end
return arr
end
end


Zeile 196: Zeile 156:
end
end


function tableToString(tbl, indent)
function p.tableToString(tbl, indent)
-- Prints a LUA-Table as string. Very useful if you want to see whats inside
-- Prints a LUA-Table as string. Very useful if you want to see whats inside
     indent = indent or 0
     indent = indent or 0
82.367

Bearbeitungen