Module:Soldier: Difference between revisions
Title-case soldier names; keep particles, suffixes, and ASN. |
Do not add unlettered MII categories when a lettered form is present |
||
| Line 1,080: | Line 1,080: | ||
end | end | ||
return after | return after | ||
end | |||
local function miiPreferredLetter(num) | |||
local ok, canon = pcall(require, 'Module:TeamCanon') | |||
if ok and type(canon) == 'table' and type(canon.letter) == 'table' then | |||
return canon.letter[tostring(num)] | |||
end | |||
return nil | |||
end | end | ||
local function noteTeamNames(text) | local function noteTeamNames(text) | ||
text = mw.ustring.upper(tostring(text or '')) | text = mw.ustring.upper(tostring(text or '')) | ||
text = mw.ustring.gsub(text, mw.ustring.char(0x2013), '-') | |||
text = mw.ustring.gsub(text, mw.ustring.char(0x2014), '-') | |||
text = mw.ustring.gsub(text, mw.ustring.char(0x2212), '-') | |||
local seen = {} | local seen = {} | ||
local names = {} | local names = {} | ||
local letteredNums = {} | |||
local function add(name) | local function add(name) | ||
if name ~= '' and not seen[name] then | if name ~= '' and not seen[name] then | ||
| Line 1,093: | Line 1,105: | ||
end | end | ||
local work = text | local work = text | ||
for num, letter in string.gmatch(work, 'MII%s+(%d+)%s*%-%s*([A-Z])') do | for num, letter in string.gmatch(work, 'MII[%s%-]+(%d+)%s*%-%s*([A-Z])') do | ||
add('MII ' .. num .. '-' .. letter) | add('MII ' .. num .. '-' .. letter) | ||
letteredNums[num] = true | |||
end | end | ||
work = string.gsub(work, 'MII%s+%d+%s*%-%s*[A-Z]', ' ') | work = string.gsub(work, 'MII[%s%-]+%d+%s*%-%s*[A-Z]', ' ') | ||
for num in string.gmatch( | for num, letter in string.gmatch(' ' .. text .. ' ', '[^%d]([45]%d%d)%s*%-%s*([A-Z])[^A-Z]') do | ||
add('MII ' .. num) | add('MII ' .. num .. '-' .. letter) | ||
letteredNums[num] = true | |||
end | end | ||
for num | for num in string.gmatch(work, 'MII[%s%-]+(%d+)') do | ||
add('MII ' .. num .. '-' .. | if not letteredNums[num] then | ||
local preferred = miiPreferredLetter(num) | |||
if preferred then | |||
add('MII ' .. num .. '-' .. preferred) | |||
else | |||
add('MII ' .. num) | |||
end | |||
end | |||
end | end | ||
for num in string.gmatch(text, 'IPW%s+(%d+)') do | for num in string.gmatch(text, 'IPW%s+(%d+)') do | ||