« Module:IdentifierRACJ » : différence entre les versions

De alcolois
Aller à la navigation Aller à la recherche
Nouvelle mouture
Nouvelle mouture qui conserve les numéros de dossier qui ont la forme dd-ddddddd-ddd
Ligne 12 : Ligne 12 :
end
end


-- Extrait tous les identifiants secondaires valides
-- Si un dd-500xxxx est présent, retourne les identifiants secondaires :
-- dd-ddddddd, dd-ddddddd-ddd, ddd-ddd, dddd-ddd
function p.extraireNoDeDossier(frame)
function p.extraireNoDeDossier(frame)
     local texte = frame.args[1] or ""
     local texte = frame.args[1] or ""
     local decision = string.match(texte, "(%d%d%-500%d%d%d%d)")
     local decision = string.match(texte, "(%d%d%-500%d%d%d%d)")
 
    local deja = {}
     local identifiants = {}
     local identifiants = {}
    local deja = {}


     if decision then
     if decision then
Ligne 31 : Ligne 31 :
         end
         end


         -- 2. ddd%-ddd (must not be part of longer match)
         -- 2. 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
                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
         for id in string.gmatch(texte, "(%f[%d]%d%d%d%-%d%d%d%f[%D])") do
             if not deja[id] then
             if not deja[id] then
Ligne 39 : Ligne 47 :
         end
         end


         -- 3. dddd%-ddd
         -- 4. dddd-ddd
         for id in string.gmatch(texte, "(%f[%d]%d%d%d%d%-%d%d%d%f[%D])") do
         for id in string.gmatch(texte, "(%f[%d]%d%d%d%d%-%d%d%d%f[%D])") do
             if not deja[id] then
             if not deja[id] then

Version du 2 juin 2025 à 18:07


local p = {}

-- Extrait un identifiant de type dd-500xxxx (prioritaire), sinon dd-ddddddd
function p.extraireNoDeDecision(frame)
    local texte = frame.args[1] or ""
    local identifiant = string.match(texte, "(%d%d%-500%d%d%d%d)")
    if identifiant then
        return identifiant
    end
    identifiant = string.match(texte, "(%d%d%-%d%d%d%d%d%d%d)")
    return identifiant or ""
end

-- Si un dd-500xxxx est présent, retourne les identifiants secondaires :
-- dd-ddddddd, dd-ddddddd-ddd, ddd-ddd, dddd-ddd
function p.extraireNoDeDossier(frame)
    local texte = frame.args[1] or ""
    local decision = string.match(texte, "(%d%d%-500%d%d%d%d)")
    local deja = {}
    local identifiants = {}

    if decision then
        deja[decision] = true

        -- 1. dd-ddddddd
        for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d)") do
            if not deja[id] then
                deja[id] = true
                table.insert(identifiants, id)
            end
        end

        -- 2. 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
                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
    end

    return table.concat(identifiants, ", ")
end

return p