示例#1
0
        private static bool IsDomainStart(char c, bool allowInternational, out SubDomainType type)
        {
            if (c < 128)
            {
                if (IsLetter(c))
                {
                    type = SubDomainType.Alphabetic;
                    return(true);
                }

                if (IsDigit(c))
                {
                    type = SubDomainType.Numeric;
                    return(true);
                }

                type = SubDomainType.None;

                return(false);
            }

            if (allowInternational)
            {
                type = SubDomainType.Alphabetic;
                return(true);
            }

            type = SubDomainType.None;

            return(false);
        }
示例#2
0
        private static bool IsDomain(char c, bool allowInternational, ref SubDomainType type)
        {
            if (c < 128)
            {
                if (IsLetter(c) || c == '-')
                {
                    type |= SubDomainType.Alphabetic;
                    return(true);
                }

                if (IsDigit(c))
                {
                    type |= SubDomainType.Numeric;
                    return(true);
                }

                return(false);
            }

            if (allowInternational)
            {
                type |= SubDomainType.Alphabetic;
                return(true);
            }

            return(false);
        }
示例#3
0
        private static bool SkipSubDomain(string text, ref int index, bool allowInternational, out SubDomainType type)
        {
            var startIndex = index;

            if (!IsDomainStart(text[index], allowInternational, out type))
            {
                return(false);
            }

            index++;

            while (index < text.Length && IsDomain(text[index], allowInternational, ref type))
            {
                index++;
            }

            return(index - startIndex < 64 && text[index - 1] != '-');
        }
示例#4
0
        static bool SkipSubDomain(string text, ref int index, bool allowInternational, out SubDomainType type)
        {
            int startIndex = index;

            if (!IsDomainStart(text[index], allowInternational, out type))
            {
                return(false);
            }

            index++;

            while (index < text.Length && IsDomain(text[index], allowInternational, ref type))
            {
                index++;
            }

            // Don't allow single-character top-level domains.
            if (index == text.Length && (index - startIndex) == 1)
            {
                return(false);
            }

            return((index - startIndex) <= 64 && text[index - 1] != '-');
        }