System.Security.Util.URLString.ParseProtocol C# (CSharp) Method

ParseProtocol() private method

private ParseProtocol ( String url ) : String
url String
return String
        private String ParseProtocol(String url)
        {
            String temp;
            int index = url.IndexOf( ':' );
                
            if (index == 0)
            {
                throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidUrl" ) );
            }
            else if (index == -1)
            {
                m_protocol = m_defaultProtocol;
                temp = url;
            }
            else if (url.Length > index + 1)
            {
                if (index == m_defaultProtocol.Length && 
                    String.Compare(url, 0, m_defaultProtocol, 0, index, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    m_protocol = m_defaultProtocol;
                    temp = url.Substring( index + 1 );
                }
                else if (url[index+1] != '\\')
                {
#if !PLATFORM_UNIX
                    if (url.Length > index + 2 &&
                        url[index+1] == '/' &&
                        url[index+2] == '/')
#else
                    if (url.Length > index + 1 &&
                        url[index+1] == '/' ) // UNIX style "file:/home/me" is allowed, so account for that
#endif  // !PLATFORM_UNIX
                    {
                        m_protocol = url.Substring( 0, index );

                        for (int i = 0; i < m_protocol.Length; ++i)
                        {
                            char c = m_protocol[i];

                            if ((c >= 'a' && c <= 'z') ||
                                (c >= 'A' && c <= 'Z') ||
                                (c >= '0' && c <= '9') ||
                                (c == '+') ||
                                (c == '.') ||
                                (c == '-'))
                            {
                                continue;
                            }
                            else
                            {
                                throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidUrl" ) );
                            }
                        }
#if !PLATFORM_UNIX
                        temp = url.Substring( index + 3 );
#else
                        // In UNIX, we don't know how many characters we'll have to skip past.
                        // Skip past \, /, and :
                        //
                        for ( int j=index ; j<url.Length ; j++ )
                        {
                            if ( url[j] != '\\' && url[j] != '/' && url[j] != ':' )
                            {
                                index = j;
                                break;
                            }
                        }

                        temp = url.Substring( index );
#endif  // !PLATFORM_UNIX
                     }                                
                    else
                    {
                        throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidUrl" ) );
                    }
                }
                else
                {
                    m_protocol = m_defaultProtocol;
                    temp = url;
                }
            }
            else
            {
                throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidUrl" ) );
            }

            return temp;
        }