Modul:Sort: Unterschied zwischen den Versionen

1.738 Bytes hinzugefügt ,  vor 12 Jahren
RELEASE num+latin
w>PerfektesChaos
(fix)
w>PerfektesChaos
(RELEASE num+latin)
Zeile 1: Zeile 1:
--[=[ 2013-10-24
--[=[ 2013-10-25
Sort
Sort
]=]
]=]
Zeile 6: Zeile 6:


local Sort = { }
local Sort = { }
Sort.lex = function ( adjust, apply, adapt )
    -- Build ASCII sortkey for text value
    -- Precondition:
    --    adjust  -- string to be aligned
    --    apply  -- string with base
    --                "latin"
    --    adapt  -- variation, or false
    --                "DIN5007m2"  -- DIN 5007 mode "2"
    local r = adjust
    if not r:match( "^[ -~]*$" ) then
        local lucky
        local collate
        if apply then
            collate = apply
        else
            collate = "uni"
        end
        if adapt then
            collate = collate .. adapt
        end
        collate = "Module:Sort/" .. collate
        lucky, collate = pcall( mw.loadData, collate )
        if type( collate ) == "table" then
            local k, n, s, start
            local n = mw.ustring.len( r )
            for i = n, 1, -1 do
                k = mw.ustring.codepoint( r, i, i )
                if k < 127 then    -- ASCII
                    s = ( k < 32 )    -- htab newline whitespace
                    if s then
                        s = " "
                    end
                else
                    s = collate[ k ]
                end
                if s then
                    if i > 1 then
                        s = mw.ustring.sub( r, 1,  i - 1 )  ..  s
                    end
                    r = s .. mw.ustring.sub( r,  i + 1 )
                end
            end    -- for i--
        else
            r = "**ERROR** Sort.lex ** Submodule unavailable " .. collate
        end
    end
    r = r:gsub( "  +", " " )
    return r
end -- Sort.lex()




Zeile 35: Zeile 87:
     local c
     local c
     if ad then
     if ad then
         mid = mw.ustring.codepoint( ad, 1 )
         mid = mw.ustring.codepoint( ad, 1, 1 )
     end
     end
     if at then
     if at then
Zeile 44: Zeile 96:
     end
     end
     for i = 1, n do
     for i = 1, n do
         c = mw.ustring.codepoint( source, i )
         c = mw.ustring.codepoint( source, i, i )
         if c > 32 then    -- not whitespace
         if c > 32 then    -- not whitespace
             if c >= 48 and c <= 57 then    -- digits
             if c >= 48 and c <= 57 then    -- digits
Zeile 52: Zeile 104:
             elseif c == mid then    -- decimal separator
             elseif c == mid then    -- decimal separator
                 for j = i + 1, n do
                 for j = i + 1, n do
                     c = mw.ustring.codepoint( source, j )
                     c = mw.ustring.codepoint( source, j, j )
                     if c >= 48 and c <= 57 then    -- digits
                     if c >= 48 and c <= 57 then    -- digits
                         sub = string.format( "%s%c", sub, c )
                         sub = string.format( "%s%c", sub, c )
Zeile 151: Zeile 203:
     -- Template::latin
     -- Template::latin
     --    {{{1}}}
     --    {{{1}}}
     return "not yet ready"
     -- #invoke
    --    v  -- variant, omitted or "DIN5007m2"
    local lucky, r = pcall( Sort.lex,
                            frame:getParent().args[ 1 ] or "",
                            "latin",
                            frame.args.v )
    return r;
end -- p.Tlatin
end -- p.Tlatin


Zeile 178: Zeile 236:
                             tonumber( frame.args.z ),
                             tonumber( frame.args.z ),
                             frame.args.m == "1" )
                             frame.args.m == "1" )
    -- DEBUG:
    if not lucky then
        r = "<span class=\"error\">" .. r .. "</span>"
    end
     return r;
     return r;
end -- p.Tn
end -- p.Tn
Anonymer Benutzer