Modul:Detect singular: Unterschied zwischen den Versionen

(fix detect return for blank input, also)
(add any_comma and no_and flags)
Zeile 25: Zeile 25:
local args = {}
local args = {}
-- canonicalize boolean arguments
-- canonicalize boolean arguments
for key, default in pairs({no_comma=false,parse_links=false}) do
for key, default in pairs({no_comma=false,parse_links=false,any_comma=false,no_and=false}) do
if origArgs[key] == nil then
if origArgs[key] == nil then
args[key] = default
args[key] = default
Zeile 33: Zeile 33:
end
end
local checkComma = not args.no_comma
local checkComma = not args.no_comma
local checkAnd = not args.no_and
local rewriteLinks = not args.parse_links
local rewriteLinks = not args.parse_links
local anyComma = args.any_comma
local s = origArgs[1]  -- the input string
local s = origArgs[1]  -- the input string
if not s then
if not s then
Zeile 66: Zeile 68:
-- For the last 4, evaluate on string stripped of wikimarkup
-- For the last 4, evaluate on string stripped of wikimarkup
s = getPlain(s)
s = getPlain(s)
local hasComma = checkComma and mw.ustring.find(s, '%D[,;]%D') -- semi-colon similar to comma
local commaPattern = anyComma and '[,;]' or '%D[,;]%D' -- semi-colon similar to comma
local hasAnd = mw.ustring.find(s,'[,%s]and%s')
local hasComma = checkComma and mw.ustring.find(s, commaPattern)
local hasAnd = checkAnd and mw.ustring.find(s,'[,%s]and%s')
local hasBullets = countMatches(s,'%*+') > 1
local hasBullets = 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