Nicht angemeldeter Benutzer - Bearbeiten von Seiten ist nur als angemeldeter Benutzer möglich.

Änderungen

Zur Navigation springen Zur Suche springen
1.346 Bytes hinzugefügt ,  21:20, 16. Feb. 2014
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
  
Cookies helfen uns bei der Bereitstellung von imedwiki. Durch die Nutzung von imedwiki erklärst du dich damit einverstanden, dass wir Cookies speichern.

Navigationsmenü