Modul:Detect singular: Unterschied zwischen den Versionen
(wrong name) |
(check for isolated "list" and "and") |
||
| Zeile 27: | Zeile 27: | ||
end | end | ||
local hasComma = checkComma and plainFind(s, ',') | local hasComma = checkComma and plainFind(s, ',') | ||
local hasList = | local hasList = mw.ustring.find(s,'%Alist%A') | ||
local hasAnd = mw.ustring.find(s,'%Aand%A') | |||
local hasBreak = mw.ustring.find(s,'<%s*br') | local hasBreak = mw.ustring.find(s,'<%s*br') | ||
local hasBullets = checkBullets and plainCount(s,'*') > 1 | local hasBullets = checkBullets and plainCount(s,'*') > 1 | ||
return not (hasComma or hasList or hasBreak or hasBullets) | return not (hasComma or hasList or hasAnd or hasBreak or hasBullets) | ||
end | end | ||
Version vom 8. Januar 2022, 06:51 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Detect singular/doc erstellt werden
local p = {}
local getArgs = require('Module:Arguments').getArgs
local yesNo = require('Module:Yesno')
local function plainFind(s, sub)
return mw.ustring.find(s, sub, 1, true)
end
local function plainCount(s, sub)
local _, count = mw.ustring.gsub(s, sub, '')
return count
end
function p._main(args)
local checkComma = not yesNo(args.no_comma,true)
local checkBullets = yesNo(args.bullets,true)
local s = args[1] -- the input string
if not s then
return nil -- empty input returns nil
end
s = tostring(s)
if plainFind(s,'forcedetectsingular') then -- magic data string to return true
return true
end
if plainFind(s,'forcedetectplural') then -- magic data string to return false
return false
end
local hasComma = checkComma and plainFind(s, ',')
local hasList = mw.ustring.find(s,'%Alist%A')
local hasAnd = mw.ustring.find(s,'%Aand%A')
local hasBreak = mw.ustring.find(s,'<%s*br')
local hasBullets = checkBullets and plainCount(s,'*') > 1
return not (hasComma or hasList or hasAnd or hasBreak or hasBullets)
end
function p.main(frame)
local args = getArgs(frame)
if p._main(args) then
return 1
end
return ""
end
return p