Content deleted Content added
No edit summary |
Undid revision 1147915801 by Lemondoge (talk): oh dear. I checked with testcases - don't know how this goofed |
||
(28 intermediate revisions by 4 users not shown) | |||
Line 1:
require('strict')
local p = {}
local getArgs = require('Module:Arguments').getArgs
local str = require('Module:String')
local yesno = require('Module:Yesno')
local iMaxWords = 16
local warningIMaxWordsReached = nil
Line 13 ⟶ 10:
local report -- to be initinated when explain needed
-- Initialise the /report subpage.
-- only invoked when
local function initReport()
report = require('Module:Str find word/report')
end
-- Turn "A" into "A" etc. asap
-- and reduce multi-spaces (including nbsp etc.) into single space
local function decodeUnicode(str)
Line 35 ⟶ 32:
-- step 1: when case-insensitive, turn string into lowercase
-- step 2: read & remove Literals ("..")
-- step 3:
-- step 4: when booleans=T, change boolean words into true/false (module:yesno rules)
-- all words returned are trimmed, TODO and all ws into single-plainspace?
-- only T/F words are edited, other words
-- return the table (a straight array)
local function buildWordTable(tArgs, sWordlist)
Line 47 ⟶ 44:
-- Step 1: case-sensitive
if yesno(tArgs.case,
sWordlist = string.lower(sWordlist)
end
Line 81 ⟶ 78:
-- Step 3: parse comma-delimited words
hitCount = 0
sWordlist = tArgs.sep .. sWordlist .. tArgs.sep
local eSep
eSep = escape_word(tArgs.
local patstring = '%f[^' .. eSep .. '][^' .. eSep .. ']+%f[' .. eSep .. ']'
report.xpMessage('2.pattern: ' .. patstring) -- dev
end▼
while hitCount <= iMaxWords do
hitCount = hitCount + 1
hitWord = str._match(
hitWord = mw.text.trim(hitWord)
if hitWord ==
-- no more words found in the string
break
Line 104 ⟶ 103:
end
-- Step 4: when read booleans, converse
-- todo: check parameter here not elsewhere
if tArgs.booleans then -- TODO if Yesno(tArgs.booleans) ...
local sBool
for i, v in ipairs(wordTable) do
Line 163:
bAND = true
end
return bAND, tHits
end
Line 226:
-- explain=testcases => WHEN in ns: template: or user: AND subpage = '/testcases' THEN show permanently
local function checkExplain(tArgs)
return false -- never. 22Mar2023 checkExplain(newArgs)
▲ if yesno(tArgs.explain, true) then
return true▼
▲ end
end
Line 274 ⟶ 260:
-- No words to check
resultALL = false
if yesno(tArgs.explain,
report.xpNoWords(tArgs, sourceWordTable, andWordTable, orWordTable)
end
Line 287 ⟶ 273:
-- concat the sYeslist (= all hit words; from 2 tables)
if bANDresult then
sYeslist = sYeslist .. table.concat(tANDhits, tArgs.
end
if #tORhits > 0 then
if #tANDhits > 0 then
sYeslist = sYeslist .. tArgs.
end
sYeslist = sYeslist .. table.concat(tORhits, tArgs.
end
end
if yesno(tArgs.explain,
if tArgs.yes ~= nil then
if (tArgs.yes == '') and (tArgs.no == '') then
Line 317 ⟶ 303:
-- set wordt separator
local function setSep(sSep)
local msg = ''
-- todo what with {{!}}
local newSep = defaultSep
▲ if sSep == nil or sSep == '' then return defaultSep end
sSep = decodeUnicode(sSep)
if string.match(sSep, '[%s%w%d]') ~= nil then -- not msg = 'Irregular characters in sep: ' .. sSep
newSep = string.sub(sSep, 1, 1)
if newSep == '' then --- ???
newSep = defaultSep
end
end
Line 341 ⟶ 331:
local function parseArgs(origArgs)
local newArgs = {}
newArgs['sep'] = setSep(origArgs['sep']
newArgs['source'] = decodeUnicode(origArgs['s'] or origArgs['source'] or '')
newArgs['andString'] = decodeUnicode(concatAndLists(
origArgs['w'] or origArgs['word'] or nil,
origArgs['andw'] or origArgs['andwords'] or nil,
newArgs.sSep) )
newArgs['orString'] = decodeUnicode(origArgs['orw'] or origArgs['orwords'] or '')
-- boolean options: catch both parameters, also handle nil & nonsense input values:
newArgs['case'] = yesno(origArgs['case'] or origArgs['casesensitive'] or
newArgs['booleans'] = yesno(origArgs['bool'] or origArgs['booleans'] or false, false) -- defaults to False
newArgs['literals'] = yesno(origArgs['literals'] or origArgs['lit'] or true, true) -- defaults to True
newArgs['yes'] = origArgs['yes'] or nil -- nil; default so return sYeslist; keep '' as legal input & return value
newArgs['no'] = origArgs['no'] or ''
newArgs['explain'] =
newArgs.explain = false -- never. 22Mar2023 checkExplain(newArgs)
return newArgs
Line 367 ⟶ 358:
tArgs = parseArgs(origArgs)
if yesno(tArgs.explain,
initReport()
report.xpListArguments(origArgs)
Line 379 ⟶ 370:
end
if yesno(tArgs.explain,
return sReturn .. report.xpPresent(tArgs.explain)
else
|