IP.Sigil (ip v2.1.3)
Provides the ~i
sigil.
You can use with import IP.Sigil
or use IP
.
Valid modifiers are f
to parse specifically as an IPv4 value, and s
to
parse specifically as an IPv6 value. As a side note, digits can't be used as
sigil modifiers. Ask me how I know.
~i
will raise IP.Sigil.InvalidValue
in the event of a parsing failure.
Examples
iex> ~i(192.0.2.1/32)
#IP.Prefix<192.0.2.1/32 Documentation (TEST-NET-1), GLOBAL, RESERVED>
iex> ~i(192.0.2.1)f
#IP.Address<192.0.2.1 Documentation (TEST-NET-1), GLOBAL, RESERVED>
iex> ~i(2001:db8::/32)
#IP.Prefix<2001:db8::/32 Documentation, GLOBAL, RESERVED>
iex> ~i(2001:db8::/32)s
#IP.Prefix<2001:db8::/32 Documentation, GLOBAL, RESERVED>
Summary
Functions
Implements sigil_i
for parsing IP addresses and prefixes.
Functions
@spec sigil_i(binary(), [non_neg_integer()]) :: IP.Prefix.t() | IP.Address.t()
Implements sigil_i
for parsing IP addresses and prefixes.
value
is a string which will be passed toIP.Prefix.from_string
andIP.Address.from_string
sequentially.options
is a charlist of flags provided to the sigil. Valid flags are:f
parse string specifically as an IPv4 value.s
parse string specifically as an IPv6 value.
Examples
iex> IP.Sigil.sigil_i("192.0.2.1", ~c"")
#IP.Address<192.0.2.1 Documentation (TEST-NET-1), GLOBAL, RESERVED>
iex> IP.Sigil.sigil_i("192.0.2.0/24", ~c"")
#IP.Prefix<192.0.2.0/24 Documentation (TEST-NET-1), GLOBAL, RESERVED>
iex> IP.Sigil.sigil_i("2001:db8::/32", ~c"")
#IP.Prefix<2001:db8::/32 Documentation, GLOBAL, RESERVED>
iex> IP.Sigil.sigil_i("2001:db8::", ~c"")
#IP.Address<2001:db8:: Documentation, GLOBAL, RESERVED>
iex> IP.Sigil.sigil_i("Marty McFly", ~c"")
** (IP.Sigil.InvalidValue) Unable to parse "Marty McFly" as an IP address or prefix.
iex> IP.Sigil.sigil_i("192.0.2.1", ~c"f")
#IP.Address<192.0.2.1 Documentation (TEST-NET-1), GLOBAL, RESERVED>
iex> IP.Sigil.sigil_i("2001:db8::/32", ~c"f")
** (IP.Sigil.InvalidValue) Unable to parse "2001:db8::/32" as an IPv4 address or prefix.
iex> IP.Sigil.sigil_i("192.0.2.1", ~c"s")
** (IP.Sigil.InvalidValue) Unable to parse "192.0.2.1" as an IPv6 address or prefix.
iex> IP.Sigil.sigil_i("2001:db8::/32", ~c"s")
#IP.Prefix<2001:db8::/32 Documentation, GLOBAL, RESERVED>