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

Nouvelle mouture
Nouvelle mouture
Ligne 13 : Ligne 13 :
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)")
   
    -- Extraire le premier identifiant, qu'il soit 500xxxx ou non
     local decision = p.extraireNoDeDecision{ args = { texte } }
    if decision == "" then return "" end
 
     local deja = {}
     local deja = {}
     local prefixesExclus = {}
     local prefixesExclus = {}
     local identifiants = {}
     local identifiants = {}
    deja[decision] = true


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


        -- 2. dd-ddddddd (exclure ceux déjà utilisés comme préfixes)
    -- 2. dd-ddddddd (sauf si déjà inclus comme préfixe)
        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
                deja[id] = true
            deja[id] = true
                table.insert(identifiants, id)
            table.insert(identifiants, id)
            end
         end
         end
    end


        -- 3. ddd-ddd
    -- 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
                deja[id] = true
            deja[id] = true
                table.insert(identifiants, id)
            table.insert(identifiants, id)
            end
         end
         end
    end


        -- 4. 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
                deja[id] = true
            deja[id] = true
                table.insert(identifiants, id)
            table.insert(identifiants, id)
            end
         end
         end
     end
     end