Modul:URLutil: Unterschied zwischen den Versionen

Anpassung
w>Hephaion
K (Hephaion verschob Seite Modul:IPAddress nach Modul:URLutil, ohne dabei eine Weiterleitung anzulegen: fix)
w>PerfektesChaos
(Anpassung)
Zeile 1: Zeile 1:
--[=[
--[=[
URLutil: Utilities for URL etc.
* getScheme()
* getDomain()
* isIP()
* isIPv4()
* isIPv6()
Only [[dotted decimal]] notation for IPv4 supported.
Does not support dotted hexadecimal, dotted octal, or single-number formats.
Functions are not "local", so other modules can require this module and call them directly.
Functions are not "local", so other modules can require this module and call them directly.
We return an object with 3 small stub functions to call the real ones so that the functions
We return an object with small stub functions to call the real ones so that the functions
can be called from templates also.
can be called from templates also.
 
----
Only [[dotted decimal]] notation for IPv4 supported. Does not support
Based upon  w:en:Special:Permalink/542839577?title=Module:IPAddress  2013-03-01
dotted hexadecimal, dotted octal, or single-number formats (see [[IPv4#Address_representations]]).
Unit tests at :en:Module:IPAddress/tests
 
Unit tests at Module:IPAddress/tests
]=]
]=]


function _isIpV6( s )
function _isIPv6( s )
     local dcolon, groups
     local dcolon, groups
     if type( s ) ~= "string"
     if type( s ) ~= "string"
Zeile 29: Zeile 36:
end
end


function _isIpV4( s )
function _isIPv4( s )
     local function legal( n ) return ( tonumber( n ) or 256 ) < 256  and not n:match("^0%d") end-- in lua 0 is true!
     local function legal( n ) return ( tonumber( n ) or 256 ) < 256  and not n:match("^0%d") end-- in lua 0 is true!
      
      
Zeile 37: Zeile 44:
end
end


function _isIp( s )
function _isIP( s )
     return _isIpV4( s ) and "4" or _isIpV6( s ) and "6"
     return _isIPv4( s ) and "4" or _isIPv6( s ) and "6"
end
end


local p = {}
local p = {}


function p.isIpV6(frame) return _isIpV6( frame.args[ 1 ] ) and "1" or "0" end
function p.isIPv6(frame) return _isIPv6( frame.args[ 1 ] ) and "1" or "0" end
function p.isIpV4(frame) return _isIpV4( frame.args[ 1 ] ) and "1" or "0" end
function p.isIPv4(frame) return _isIPv4( frame.args[ 1 ] ) and "1" or "0" end
function p.isIp(frame) return _isIp( frame.args[ 1 ] ) or "" end
function p.isIP(frame) return _isIP( frame.args[ 1 ] ) or "" end


return p
return p
Anonymer Benutzer