_DomainName.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Net / System / _DomainName.cs / 2 / _DomainName.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

using System.Globalization; 
 
namespace System {
 
    // The class designed as to keep working set of Uri class as minimal.
    // The idea is to stay with static helper methods and strings
    internal class DomainNameHelper {
 
        const char c_DummyChar = (char)0xFFFF;     //An Invalid Unicode character used as a dummy char passed into the parameter
 
        private DomainNameHelper(){ 
        }
 
        internal const string Localhost = "localhost";
        internal const string Loopback = "loopback";

        internal static string ParseCanonicalName(string str,int start, int end, ref bool loopback) { 
            string res = null;
 
            for (int i = end-1; i >= start; --i) { 
                if (str[i] >= 'A' && str[i] <= 'Z') {
                    res = str.Substring(start, end-start).ToLower(CultureInfo.InvariantCulture); 
                    break;
                }
                if (str[i] == ':')
                    end = i; 
            }
 
            if (res == null) { 
                res = str.Substring(start, end-start);
            } 

            if (res == Localhost || res == Loopback) {
                loopback = true;
                return Localhost; 
            }
            return res; 
        } 
        //
        // IsValid 
        //
        //  Determines whether a string is a valid domain name
        //
        //      subdomain -> 

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK