Modul:Detect singular: Unterschied zwischen den Versionen
simplify logic a bit
(an entry in a list should always be singular, also) |
(simplify logic a bit) |
||
Zeile 25: | Zeile 25: | ||
end | end | ||
if plainFind(s,'forcedetectplural') then -- magic data string to return false | if plainFind(s,'forcedetectplural') then -- magic data string to return false | ||
return false | |||
end | |||
-- count number of list items | |||
local numListItems = countMatches(s,'<%s*li') | |||
-- if exactly one, then singular, if more than one, then plural | |||
if numListItems == 1 then | |||
return true | |||
end | |||
if numListItems > 1 then | |||
return false | return false | ||
end | end | ||
-- replace all wikilinks with fixed string | -- replace all wikilinks with fixed string | ||
s = mw.ustring.gsub(s,'%b[]','WIKILINK') | s = mw.ustring.gsub(s,'%b[]','WIKILINK') | ||
local hasComma = checkComma and mw.ustring.find(s, '%a,%s') | local hasComma = checkComma and mw.ustring.find(s, '%a,%s') | ||
local hasAnd = mw.ustring.find(s,'%Aand%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 countMatches(s,'%*+') > 1 | local hasBullets = checkBullets and countMatches(s,'%*+') > 1 | ||
local multipleQids = mw.ustring.find(s,'Q%d+[%p%s]+Q%d+') -- has multiple QIDs in a row | local multipleQids = mw.ustring.find(s,'Q%d+[%p%s]+Q%d+') -- has multiple QIDs in a row | ||
return not (hasComma | return not (hasComma or hasAnd or hasBreak or hasBullets or multipleQids) | ||
end | end | ||