Modul:WLink: Unterschied zwischen den Versionen

Zur Navigation springen Zur Suche springen
267 Bytes hinzugefügt ,  5. Oktober 2016
2016-10-05
wp>PerfektesChaos
(2016-07-20)
wp>PerfektesChaos
(2016-10-05)
Zeile 1: Zeile 1:
local WLink = { suite  = "WLink",
local WLink = { suite  = "WLink",
                 serial = "2016-07-20" };
                 serial = "2016-10-05" };
--[=[
--[=[
ansiPercent()
ansiPercent()
Zeile 269: Zeile 269:




function target( attempt, lonely )
local target = function ( attempt, lonely )
     -- Retrieve first target (wikilink or URL), or entire string
     -- Retrieve first target (wikilink or URL), or entire string
     -- Precondition:
     -- Precondition:
Zeile 296: Zeile 296:




function WLink.ansiPercent( attempt )
function WLink.ansiPercent( attempt, alter )
     -- Convert string by ANSI encoding rather than UTF-8 encoding
     -- Convert string by ANSI encoding rather than UTF-8 encoding
     -- Precondition:
     -- Precondition:
     --    attempt  -- string, with presumable ANSI characters
     --    attempt  -- string, with presumable ANSI characters
    --    alter    -- string or nil, to use for spaces instead of %20
     -- Postcondition:
     -- Postcondition:
     --    Returns  string, encoded
     --    Returns  string, encoded
     local k, s;
     local k, s;
     local r = attempt;
     local r = attempt;
     for i = mw.ustring.len( attempt ), 1, -1 do
    if alter then
         k = mw.ustring.codepoint( attempt, i, i );
        r = r:gsub( " ", alter );
    end
     for i = mw.ustring.len( r ), 1, -1 do
         k = mw.ustring.codepoint( r, i, i );
         if k <= 32  or  k > 126 then
         if k <= 32  or  k > 126 then
             if k > 255 then
             if k > 255 then
                 s = mw.ustring.sub( attempt, i, i );
                 s = mw.ustring.sub( r, i, i );
                 if k > 2047 then
                 if k > 2047 then
                     s = string.format( "%%%2X%%%2X%%%2X",
                     s = string.format( "%%%2X%%%2X%%%2X",
Zeile 323: Zeile 327:
             end
             end
             r = string.format( "%s%s%s",
             r = string.format( "%s%s%s",
                               mw.ustring.sub( attempt,  1,  i - 1 ),
                               mw.ustring.sub( r,  1,  i - 1 ),
                               s,
                               s,
                               mw.ustring.sub( r,  i + 1 ) );
                               mw.ustring.sub( r,  i + 1 ) );
Zeile 1.111: Zeile 1.115:
     -- Postcondition:
     -- Postcondition:
     --    Return string; might be error message
     --    Return string; might be error message
    local k, v;
     local lucky = true;
     local lucky = true;
     local s = false;
     local s = false;
     local r = false;
     local r = false;
    local space;
     for k, v in pairs( frame.args ) do
     for k, v in pairs( frame.args ) do
         if k == 1 then
         if k == 1 then
Zeile 1.121: Zeile 1.125:
             else
             else
                 s = mw.text.trim( v );
                 s = mw.text.trim( v );
            end
        elseif action == "ansiPercent"  and  k == "space" then
            if v ~= "" then
                space = v;
             end
             end
         elseif k ~= "template" then
         elseif k ~= "template" then
Zeile 1.134: Zeile 1.142:
     if lucky then
     if lucky then
         if s or lone then
         if s or lone then
             lucky, r = pcall( WLink[ action ], s );
             lucky, r = pcall( WLink[ action ], s,  space );
         else
         else
             r = "Parameter missing";
             r = "Parameter missing";
Anonymer Benutzer

Navigationsmenü