Exemplo n.º 1
0
        /// <summary>
        /// Whether a host string is an <c>IP-literal</c> (see 3.2.2).
        /// </summary>
        /// <param name="value">The string to test.</param>
        public static bool HostIsIpLiteral(string value)
        {
            if (!value.StartsWith("[") || !value.EndsWith("]"))
            {
                return(false);
            }
            if (HostIPvFutureRegex.IsMatch(value))
            {
                return(true);
            }
            var octets = new byte[16];

            return(TryParseIpV6Address(value.Substring(1, value.Length - 2), octets, out string zoneId));
        }
        /// <summary>
        /// Whether a host string is an <c>IP-literal</c> (see 3.2.2).
        /// </summary>
        /// <param name="value">The string to test.</param>
        public static bool HostIsIpLiteral(string value)
        {
            _ = value ?? throw new ArgumentNullException(nameof(value));
            if (!value.StartsWith("[", StringComparison.Ordinal) || !value.EndsWith("]", StringComparison.Ordinal))
            {
                return(false);
            }
            if (HostIPvFutureRegex.IsMatch(value))
            {
                return(true);
            }
            var octets = new byte[16];

            return(TryParseIpV6Address(value.Substring(1, value.Length - 2), octets, out var zoneId));
        }
 /// <summary>
 /// Whether a host string is an <c>IPvFuture</c> (see 3.2.2).
 /// </summary>
 /// <param name="value">The string to test.</param>
 public static bool HostIsFutureIpLiteral(string value) => HostIPvFutureRegex.IsMatch(value);