Esempio n. 1
0
 public static string InvertHost(string host)
 {
     if (HostUtils.IsNumeric(host))
     {
         return(host);
     }
     else
     {
         int    n   = host.Length;
         char[] res = new char[n];
         int    a   = 0;
         while (a < n)
         {
             int c = a;
             while (c < n && host[c] != '.')
             {
                 c++;
             }
             int d = n - c;
             while (a < c)
             {
                 res[d++] = host[a++];
             }
             res[d++] = '.';
             a        = c + 1;
         }
         return(new string(res));
     }
 }
Esempio n. 2
0
        public static string DomainOf(string host)
        {
            if (HostUtils.IsNumeric(host))
            {
                return(host);
            }
            int n = host.Length;

            for (int i = 0; i < suffix.Length; i++)
            {
                if (host.EndsWith(suffix[i]))
                {
                    int p = LastDotBefore(host, n - suffix[i].Length);
                    if (p == -1)
                    {
                        return(host);
                    }
                    return(host.Substring(p + 1));
                }
            }
            int q = LastDotBefore(host, n);

            if (q == -1)
            {
                return(host);
            }
            int r = LastDotBefore(host, q);

            if (r == -1)
            {
                return(host);
            }
            return(host.Substring(r + 1));
        }