Zum Inhalt springen

Modul:Text: Unterschied zwischen den Versionen

1.346 Bytes hinzugefügt ,  vor 11 Jahren
update; + Modul:TextUtil
w>Leyo
K (Schützte „Modul:Text“ ([Bearbeiten=Nur angemeldete, nicht neue Benutzer] (unbeschränkt) [Verschieben=Nur Administratoren] (unbeschränkt)))
w>PerfektesChaos
(update; + Modul:TextUtil)
Zeile 1: Zeile 1:
--[=[ 2013-11-07
--[=[ 2014-02-15
Text utilities
Text utilities
]=]
]=]
Zeile 9: Zeile 9:
local patternLatin      = false
local patternLatin      = false
local patternTerminated = false
local patternTerminated = false
Text.concatParams = function ( args, apply )
    -- Concat list items into one string
    -- Parameter:
    --    args  -- table (sequence) with numKey=string
    --    apply  -- string (optional); separator (default: "|")
    -- Returns: string
end -- Text.concatParams()




Zeile 17: Zeile 27:
     --    analyse  -- string
     --    analyse  -- string
     -- Returns: true, if CJK detected
     -- Returns: true, if CJK detected
    local r
     if not patternCJK then
     if not patternCJK then
         patternCJK = mw.ustring.char( 91,
         patternCJK = mw.ustring.char( 91,
Zeile 30: Zeile 41:
     return r
     return r
end -- Text.containsCJK()
end -- Text.containsCJK()
Text.listToText = function ( args, adapt )
    -- Format list items similar to mw.text.listToText()
    -- Parameter:
    --    args  -- table (sequence) with numKey=string
    --    adapt  -- string (optional); format including "%s"
    -- Returns: string
    local collect = { }
    for k, v in pairs( args ) do
        if type( k ) == "number" then
            v = mw.text.trim( v )
            if v ~= "" then
                if adapt then
                    v = mw.ustring.format( adapt, v )
                end
                table.insert( collect, v )
            end
        end
    end
    return mw.text.listToText( collect )
end -- Text.listToText()




Zeile 94: Zeile 128:
         for i = 1, n do
         for i = 1, n do
             c = mw.ustring.codepoint( adjust, i, i )
             c = mw.ustring.codepoint( adjust, i, i )
             if c > 32 then
             if c > 64 then
                 if flat( c ) then
                 if flat( c ) then
                     if j then
                     if j then
Zeile 123: Zeile 157:
             end
             end
         end -- for i
         end -- for i
         if j  and m < n then
         if not or m then
            r = r .. mw.ustring.sub( adjust, k )
        else
             r = form( n )
             r = form( n )
        else
            r = r .. mw.ustring.sub( adjust, k )
         end
         end
     end
     end
Zeile 139: Zeile 173:
function p.containsCJK( frame )
function p.containsCJK( frame )
     return Text.containsCJK( frame.args[ 1 ] or "" ) and "1" or ""
     return Text.containsCJK( frame.args[ 1 ] or "" ) and "1" or ""
end
function p.listToText( frame )
    local args
    local template = frame.args.template
    if type( template ) == "string" then
        template = mw.text.trim( template )
        template = ( template == "1" )
    end
    if template then
        args = frame:getParent().args
    else
        args = frame.args
    end
    return Text.listToText( frame.args, frame.args.format )
end
end


Anonymer Benutzer