Anonymous user
Module:IPAddress: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
include changes from sandbox to remove global functions (undesirable and don't appear to be needed) and related to style; then can focus on proposed changes in sandbox
(update from Module:IPAddress/sandbox with new isIpOrRange function per Module talk:IPAddress#isIpOrRange) |
(include changes from sandbox to remove global functions (undesirable and don't appear to be needed) and related to style; then can focus on proposed changes in sandbox) |
||
Line 1:
local p = {}▼
▲function _isIpV6( s )
local dcolon, groups
if type(
or s:len() == 0
or s:find(
or s:find(
or s:find(
or s:find(
then
return false
end
s, dcolon = s:gsub(
if dcolon > 1 then return false end -- at most one ::
s = s:gsub(
s, groups = s:gsub(
return ( (
and ( s:len() == 0 or (
end
function p._isIpV4(
local function legal(
▲ if type( s ) ~= "string" then return false end
▲ local p1, p2, p3, p4 = s:match( "^(%d+)%.(%d+)%.(%d+)%.(%d+)$" )
▲ return legal( p1 ) and legal( p2 ) and legal( p3 ) and legal( p4 )
end
function p._isIp(
return p._isIpV4(
end
▲local p = {}
function p.
▲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.isIpOrRange(frame)
|