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

Änderungen

Zur Navigation springen Zur Suche springen
878 Bytes hinzugefügt ,  14:32, 21. Sep. 2014
updates
Zeile 1: Zeile 1: −
--[=[ URLutil 2014-09-08
+
--[=[ URLutil 2014-09-20
 
Utilities for URL etc. on www.
 
Utilities for URL etc. on www.
 
* getAuthority()
 
* getAuthority()
Zeile 17: Zeile 17:  
* isDomain()
 
* isDomain()
 
* isDomainExample()
 
* isDomainExample()
 +
* isDomainInt()
 
* isHost()
 
* isHost()
 
* isIP()
 
* isIP()
Zeile 58: Zeile 59:     
local getTopDomain = function ( url, mode )
 
local getTopDomain = function ( url, mode )
     local host = URLutil.getHost( url )
+
     local r = URLutil.getHost( url )
     if host then
+
     if r then
         local pattern = "[%w%%]+%.[a-z][a-z]+)$"
+
         local pattern = "[%w%%]+%.%a[%w-]*%a)$"
 
         if mode == 3 then
 
         if mode == 3 then
 
             pattern = "[%w%%]+%." .. pattern
 
             pattern = "[%w%%]+%." .. pattern
 
         end
 
         end
         host = mw.ustring.match( "." .. host,  "%.(" .. pattern )
+
         r = mw.ustring.match( "." .. r,  "%.(" .. pattern )
         if host then
+
         if not r then
             return host
+
             r = false
 
         end
 
         end
 +
    else
 +
        r = false
 
     end
 
     end
     return false
+
     return r
 
end -- getTopDomain()
 
end -- getTopDomain()
   Zeile 75: Zeile 78:     
URLutil.getAuthority = function ( url )
 
URLutil.getAuthority = function ( url )
 +
    local r
 
     if type( url ) == "string" then
 
     if type( url ) == "string" then
         local s, host, colon, port
+
         local colon, host, port
 
         local pattern = "^%s*%w*:?//([%w%.%%-]+)(:?)([%d]*)/"
 
         local pattern = "^%s*%w*:?//([%w%.%%-]+)(:?)([%d]*)/"
         local i = url:find( "#", 6, true )
+
        local s = mw.text.decode( url )
 +
         local i = s:find( "#", 6, true )
 
         if i then
 
         if i then
             s = url:sub( 1,  i - 1 )  ..  "/"
+
             s = s:sub( 1,  i - 1 )  ..  "/"
 
         else
 
         else
             s = url .. "/"
+
             s = s .. "/"
 
         end
 
         end
 
         host, colon, port = mw.ustring.match( s, pattern )
 
         host, colon, port = mw.ustring.match( s, pattern )
Zeile 89: Zeile 94:  
             if colon == ":" then
 
             if colon == ":" then
 
                 if port:find( "^[1-9]" ) then
 
                 if port:find( "^[1-9]" ) then
                     return ( host .. ":" .. port )
+
                     r = ( host .. ":" .. port )
 
                 end
 
                 end
 
             elseif #port == 0 then
 
             elseif #port == 0 then
                 return host
+
                 r = host
 
             end
 
             end
 
         end
 
         end
 +
    else
 +
        r = false
 
     end
 
     end
     return false
+
     return r
 
end -- URLutil.getAuthority()
 
end -- URLutil.getAuthority()
   Zeile 104: Zeile 111:  
     local r
 
     local r
 
     if type( url ) == "string" then
 
     if type( url ) == "string" then
         local i = url:find( "#", 1, true )
+
        local s = mw.text.decode( url )
 +
         local i = s:find( "#", 1, true )
 
         if i then
 
         if i then
             r = mw.text.trim( url:sub( i ) ):sub( 2 )
+
             r = mw.text.trim( s:sub( i ) ):sub( 2 )
 
             if type( decode ) == "string" then
 
             if type( decode ) == "string" then
 
                 local encoding = mw.text.trim( decode )
 
                 local encoding = mw.text.trim( decode )
Zeile 133: Zeile 141:     
URLutil.getHost = function ( url )
 
URLutil.getHost = function ( url )
     local auth = URLutil.getAuthority( url )
+
     local r = URLutil.getAuthority( url )
     if auth then
+
     if r then
         return mw.ustring.match( auth, "^([%w%.%%-]+):?[%d]*$" )
+
         r = mw.ustring.match( r, "^([%w%.%%-]+):?[%d]*$" )
 
     end
 
     end
     return false
+
     return r
 
end -- URLutil.getHost()
 
end -- URLutil.getHost()
   Zeile 149: Zeile 157:  
             r = false
 
             r = false
 
         else
 
         else
             local i = r:find( "#", 1, true )
+
             local i
 +
            r = mw.text.decode( r )
 +
            i = r:find( "#", 1, true )
 
             if i then
 
             if i then
 
                 if i == 1 then
 
                 if i == 1 then
Zeile 290: Zeile 300:  
     local r
 
     local r
 
     if type( url ) == "string" then
 
     if type( url ) == "string" then
         local prot, colon, slashes = url:match( "^%s*([a-zA-Z]*)(:?)(//)" )
+
         local pattern = "^%s*([a-zA-Z]*)(:?)(//)"
 +
        local prot, colon, slashes = url:match( pattern )
 
         r = false
 
         r = false
 
         if slashes == "//" then
 
         if slashes == "//" then
Zeile 310: Zeile 321:     
URLutil.getTLD = function ( url )
 
URLutil.getTLD = function ( url )
     local host = URLutil.getHost( url )
+
     local r = URLutil.getHost( url )
     if host then
+
     if r then
         host = mw.ustring.match( host, "[%w]+%.([a-z][a-z]+)$" )
+
         r = mw.ustring.match( r, "[%w]+%.(%a[%w-]*%a)$" )
         return host or false
+
         if not r then
 +
            r = false
 +
        end
 
     end
 
     end
     return false
+
     return r
 
end -- URLutil.getTLD()
 
end -- URLutil.getTLD()
   Zeile 333: Zeile 346:     
URLutil.isAuthority = function ( s )
 
URLutil.isAuthority = function ( s )
 +
    local r
 
     if type( s ) == "string" then
 
     if type( s ) == "string" then
         local host, colon, port = mw.ustring.match( s, "^%s*([%w%.%%-]+)(:?)(%d*)%s*$" )
+
         local pattern = "^%s*([%w%.%%-]+)(:?)(%d*)%s*$"
 +
        local host, colon, port = mw.ustring.match( s, pattern )
 
         if colon == ":" then
 
         if colon == ":" then
 
             port = port:match( "^[1-9][0-9]*$" )
 
             port = port:match( "^[1-9][0-9]*$" )
 
             if type( port ) ~= "string" then
 
             if type( port ) ~= "string" then
                 return false
+
                 r = false
 
             end
 
             end
 
         elseif port ~= "" then
 
         elseif port ~= "" then
             return false
+
             r = false
 
         end
 
         end
         return URLutil.isHost( host )
+
         r = URLutil.isHost( host )
 +
    else
 +
        r = nil
 
     end
 
     end
     return false
+
     return r
 
end -- URLutil.isAuthority()
 
end -- URLutil.isAuthority()
   Zeile 351: Zeile 368:     
URLutil.isDomain = function ( s )
 
URLutil.isDomain = function ( s )
 +
    local r
 
     if type( s ) == "string" then
 
     if type( s ) == "string" then
         s = mw.ustring.match( s, "^%s*([%w%.%%-]+%w)%.[a-zA-Z][a-zA-Z]+%s*$" )
+
         local scan = "^%s*([%w%.%%-]+%w)%.(%a[%w-]*%a)%s*$"
 +
        local scope
 +
        s, scope = mw.ustring.match( s, scan )
 
         if type( s ) == "string" then
 
         if type( s ) == "string" then
 
             if mw.ustring.find( s, "^%w" ) then
 
             if mw.ustring.find( s, "^%w" ) then
 
                 if mw.ustring.find( s, "..", 1, true ) then
 
                 if mw.ustring.find( s, "..", 1, true ) then
                     return false
+
                     r = false
 
                 else
 
                 else
                     return true
+
                     r = true
 
                 end
 
                 end
 
             end
 
             end
 
         end
 
         end
 +
    else
 +
        r = nil
 
     end
 
     end
     return false
+
     return r
 
end -- URLutil.isDomain()
 
end -- URLutil.isDomain()
   Zeile 384: Zeile 406:  
     return r
 
     return r
 
end -- URLutil.isDomainExample()
 
end -- URLutil.isDomainExample()
 +
 +
 +
 +
URLutil.isDomainInt = function ( url )
 +
    -- Internationalized Domain Name (Punycode)
 +
    local r = URLutil.getHost( url )
 +
    if r then
 +
        if r:match( "^[!-~]+$" ) then
 +
            local s = "." .. r
 +
            if s:find( ".xn--", 1, true ) then
 +
                r = true
 +
            else
 +
                r = false
 +
            end
 +
        else
 +
            r = true
 +
        end
 +
    end
 +
    return r
 +
end -- URLutil.isDomainInt()
      Zeile 444: Zeile 486:  
               return ( tonumber( n ) < 256 )
 
               return ( tonumber( n ) < 256 )
 
           end
 
           end
 +
    local r = false
 
     if type( s ) == "string" then
 
     if type( s ) == "string" then
 
         local p1, p2, p3, p4 = s:match( "^%s*([1-9][0-9]?[0-9]?)%.([12]?[0-9]?[0-9])%.([12]?[0-9]?[0-9])%.([12]?[0-9]?[0-9])%s*$" )
 
         local p1, p2, p3, p4 = s:match( "^%s*([1-9][0-9]?[0-9]?)%.([12]?[0-9]?[0-9])%.([12]?[0-9]?[0-9])%.([12]?[0-9]?[0-9])%s*$" )
 
         if p1 and p2 and p3 and p4 then
 
         if p1 and p2 and p3 and p4 then
             return legal( p1 ) and legal( p2 ) and legal( p3 ) and legal( p4 )
+
             r = legal( p1 ) and legal( p2 ) and legal( p3 ) and legal( p4 )
 
         end
 
         end
 
     end
 
     end
     return false
+
     return r
 
end -- URLutil.isIPv4()
 
end -- URLutil.isIPv4()
   Zeile 693: Zeile 736:  
function p.isDomainExample( frame )
 
function p.isDomainExample( frame )
 
     return URLutil.isDomainExample( frame.args[ 1 ] ) and "1" or ""
 
     return URLutil.isDomainExample( frame.args[ 1 ] ) and "1" or ""
 +
end
 +
function p.isDomainInt( frame )
 +
    return URLutil.isDomainInt( frame.args[ 1 ] ) and "1" or ""
 
end
 
end
 
function p.isHost( frame )
 
function p.isHost( frame )
Cookies helfen uns bei der Bereitstellung von imedwiki. Durch die Nutzung von imedwiki erklärst du dich damit einverstanden, dass wir Cookies speichern.

Navigationsmenü