« Module:IdentifierRACJ » : différence entre les versions
Aller à la navigation
Aller à la recherche
Nouvelle version bogue capture en double |
Nouvelle version |
||
| Ligne 1 : | Ligne 1 : | ||
local p = {} | local p = {} | ||
-- Extrait : dd-500xxxx prioritairement, sinon dd-ddddddd qui n’est pas suivi de -ddd | |||
function p.extraireNoDeDecision(frame) | function p.extraireNoDeDecision(frame) | ||
local texte = frame.args[1] or "" | local texte = frame.args[1] or "" | ||
-- 1. Match | -- 1. Match dd-500xxxx | ||
local identifiant = string.match(texte, "(%f[%d]%d%d%-500%d%d%d%d%f[%D])") | local identifiant = string.match(texte, "(%f[%d]%d%d%-500%d%d%d%d%f[%D])") | ||
if identifiant then | if identifiant then | ||
| Ligne 10 : | Ligne 11 : | ||
end | end | ||
-- 2. | -- 2. Trouver le premier identifiant de type dd-ddddddd qui N’EST PAS suivi d’un -ddd | ||
for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d)") do | for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d)") do | ||
local | local suffix = string.match(texte, id .. "%-(%d%d%d)") | ||
if not | if not suffix then | ||
return id | return id | ||
end | end | ||
| Ligne 21 : | Ligne 22 : | ||
end | end | ||
-- Extrait tous les identifiants sauf celui de décision | |||
function p.extraireNoDeDossier(frame) | function p.extraireNoDeDossier(frame) | ||
local texte = frame.args[1] or "" | local texte = frame.args[1] or "" | ||
-- | -- Utilise la fonction précédente pour déterminer ce qui doit être exclu | ||
local decision = p.extraireNoDeDecision{ args = { texte } } | local decision = p.extraireNoDeDecision{ args = { texte } } | ||
local deja = { [decision] = true } | |||
local deja = {} | |||
local prefixesExclus = {} | local prefixesExclus = {} | ||
local identifiants = {} | local identifiants = {} | ||
-- 1. dd-ddddddd-ddd | -- 1. dd-ddddddd-ddd | ||
| Ligne 42 : | Ligne 41 : | ||
end | end | ||
-- 2. dd-ddddddd (sauf | -- 2. dd-ddddddd (sauf préfixes déjà capturés) | ||
for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d)") do | for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d)") do | ||
if not deja[id] and not prefixesExclus[id] then | if not deja[id] and not prefixesExclus[id] then | ||
Version du 2 juin 2025 à 18:54
local p = {}
-- Extrait : dd-500xxxx prioritairement, sinon dd-ddddddd qui n’est pas suivi de -ddd
function p.extraireNoDeDecision(frame)
local texte = frame.args[1] or ""
-- 1. Match dd-500xxxx
local identifiant = string.match(texte, "(%f[%d]%d%d%-500%d%d%d%d%f[%D])")
if identifiant then
return identifiant
end
-- 2. Trouver le premier identifiant de type dd-ddddddd qui N’EST PAS suivi d’un -ddd
for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d)") do
local suffix = string.match(texte, id .. "%-(%d%d%d)")
if not suffix then
return id
end
end
return ""
end
-- Extrait tous les identifiants sauf celui de décision
function p.extraireNoDeDossier(frame)
local texte = frame.args[1] or ""
-- Utilise la fonction précédente pour déterminer ce qui doit être exclu
local decision = p.extraireNoDeDecision{ args = { texte } }
local deja = { [decision] = true }
local prefixesExclus = {}
local identifiants = {}
-- 1. dd-ddddddd-ddd
for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d%-%d%d%d)") do
if not deja[id] then
deja[id] = true
prefixesExclus[string.match(id, "^(%d%d%-%d%d%d%d%d%d%d)")] = true
table.insert(identifiants, id)
end
end
-- 2. dd-ddddddd (sauf préfixes déjà capturés)
for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d)") do
if not deja[id] and not prefixesExclus[id] then
deja[id] = true
table.insert(identifiants, id)
end
end
-- 3. ddd-ddd
for id in string.gmatch(texte, "(%f[%d]%d%d%d%-%d%d%d%f[%D])") do
if not deja[id] then
deja[id] = true
table.insert(identifiants, id)
end
end
-- 4. dddd-ddd
for id in string.gmatch(texte, "(%f[%d]%d%d%d%d%-%d%d%d%f[%D])") do
if not deja[id] then
deja[id] = true
table.insert(identifiants, id)
end
end
return table.concat(identifiants, ", ")
end
return p