Modul:Link utilities: Unterschied zwischen den Versionen
KKeine Bearbeitungszusammenfassung |
(Wartung, Kommentare) |
||
| Zeile 1: | Zeile 1: | ||
-- documentation | |||
local LinkBase = { | |||
suite = 'LinkBase', | |||
serial = '2019-07-09', | |||
item = 65228027 | |||
} | |||
-- module variable | |||
local lb = {} | local lb = {} | ||
| Zeile 29: | Zeile 37: | ||
end | end | ||
-- extract comment written in parentheses | |||
-- remove spaces between value like phone numbers and comment | |||
function lb.extractComment( s ) | function lb.extractComment( s ) | ||
local comment = '' | local comment = '' | ||
local t = mw.ustring.gsub( s, '(.*)(%(.*%))$', '%2' ) | local t = mw.ustring.gsub( s, '(.*)(%(.*%))$', '%2' ) | ||
if t ~= s then | if t ~= s then | ||
| Zeile 41: | Zeile 49: | ||
end | end | ||
-- add error category and hint | |||
-- catPrefix contains opening squared brackets | |||
function lb.errorInfo( catPrefix, aCat, aClass ) | function lb.errorInfo( catPrefix, aCat, aClass ) | ||
aClass = aClass or 'error' | aClass = aClass or 'error' | ||
return catPrefix .. aCat .. ']]' .. '<span class="' .. aClass .. '" title="' | |||
.. aCat .. '">' .. aCat .. '</span>' | |||
end | end | ||
return lb | return lb | ||
Version vom 9. Juli 2019, 06:57 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Link utilities/doc erstellt werden
-- documentation
local LinkBase = {
suite = 'LinkBase',
serial = '2019-07-09',
item = 65228027
}
-- module variable
local lb = {}
-- split separate items like numbers
function lb.splitItems( s, delimiters, defaultDelimiter )
local i
defaultDelimiter = defaultDelimiter or ','
-- wrap delimiters with zero marks
s = mw.ustring.gsub( s, defaultDelimiter, '\0' .. defaultDelimiter .. '\0' );
-- substitude delimiters
for i = 1, #delimiters, 1 do
s = mw.ustring.gsub( s, delimiters[i], '\0' .. delimiters[i] .. '\0' );
-- remove zero marks from inside parentheses ()
s = mw.ustring.gsub( s, '%b()', function( t ) return mw.ustring.gsub( t, '%z', '' ) end )
-- replace delimeters by the default delimiter
s = mw.ustring.gsub( s, '\0' .. delimiters[i] .. '\0', '\0' .. defaultDelimiter .. '\0' );
end
-- results to an array
s = mw.text.split( s, '\0' .. defaultDelimiter .. '\0' )
for i = #s, 1, -1 do
s[ i ] = mw.text.trim( s[ i ] )
if s[ i ] == '' then
table.remove( s, i )
end
end
return s
end
-- extract comment written in parentheses
-- remove spaces between value like phone numbers and comment
function lb.extractComment( s )
local comment = ''
local t = mw.ustring.gsub( s, '(.*)(%(.*%))$', '%2' )
if t ~= s then
comment = t
s = mw.ustring.gsub( mw.ustring.gsub( s, '(.*)(%(.*%))$', '%1' ), '( +)$', '' )
end
return s, comment
end
-- add error category and hint
-- catPrefix contains opening squared brackets
function lb.errorInfo( catPrefix, aCat, aClass )
aClass = aClass or 'error'
return catPrefix .. aCat .. ']]' .. '<span class="' .. aClass .. '" title="'
.. aCat .. '">' .. aCat .. '</span>'
end
return lb