Module:Canada by province category navigation/sandbox: Difference between revisions

Content deleted Content added
Create sandbox version of Module:CanadaByProvinceCatNav
 
simplifying regex and assignment
Tag: Reverted
Line 238:
 
local function patternSearchEncode(s)
return mw.ustring.gsub(s, "([%W])", "%%%1")
end
 
Line 279:
 
debugLog(4, "match at start, followed by separator? ")
if mw.ustring.match(pn, "^" .. testProvinceEncoded .. "[^%w]W") then
debugLog(nil, "Yes")
return testProvince
Line 286:
debugLog(4, "match at end, preceded by separator? ")
if mw.ustring.match(pn, "[^%w]W" .. testProvinceEncoded .. "$") then
debugLog(nil, "Yes")
return testProvince
Line 293:
 
debugLog(4, "match anywhere, preceded and followed by separator? ")
if mw.ustring.match(pn, "[^%w]W" .. testProvinceEncoded .. "[^%w]W") then
debugLog(nil, "Yes")
return testProvince
Line 311:
local testProvinceStrippedEncoded = patternSearchEncode(testProvinceStripped)
debugLog(4, "test pattern without leading definite article, i.e. '" .. testProvinceStrippedEncoded .. "' ? ")
if (mw.ustring.match(pn, "[^%w]W" .. testProvinceStrippedEncoded .. "[^%w]W") ~= nil)
or (mw.ustring.match(pn, "^" .. testProvinceStrippedEncoded .. "[^%w]W") ~= nil)
or (mw.ustring.match(pn, "[^%w]W" .. testProvinceStrippedEncoded .. "$") ~= nil)
or (mw.ustring.match(pn, "^" .. testProvinceStrippedEncoded .. "$") ~= nil) then
debugLog(nil, "Yes")
Line 337:
debugLog(2, "split pagename around [" .. validprovinceName .. "]")
local validProvinceEncoded = mw.ustring.gsub(validprovinceName, "([%W])", "%%%1")
match_prefixtitle_prefix, match_province, match_suffixtitle_suffix = mw.ustring.match(pn, "^(.*)(" .. validProvinceEncoded .. ")(.*)$")
title_prefix = match_prefix
title_suffix = match_suffix
debugLog(2, "parse successful")
debugLog(3, "title_prefix = [" .. title_prefix .. "]")