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

ParsePort() private method

private ParsePort ( String url ) : String
url String
return String
        private String ParsePort(String url)
        {
            String temp = url;
            char[] separators = new char[] { ':', '/' };
            int Rindex = 0;
            int userpassIndex = temp.IndexOf('@');
            if (userpassIndex != -1) {
                if (temp.IndexOf('/',0,userpassIndex) == -1) {
                    // this is a user:pass type of string 
                    m_userpass = temp.Substring(0,userpassIndex);
                    Rindex = userpassIndex + 1;
                }
            }

            int braIndex = -1;
            int ketIndex = -1;
            int portIndex = -1;
            braIndex = url.IndexOf('[',Rindex);
            if (braIndex != -1)
                ketIndex = url.IndexOf(']', braIndex);
            if (ketIndex != -1)
            {
                // IPv6 address...ignore the IPv6 block when searching for the port
                portIndex = temp.IndexOfAny(separators,ketIndex);
            }
            else
            {
                portIndex = temp.IndexOfAny(separators,Rindex);
            }

            

            if (portIndex != -1 && temp[portIndex] == ':')
            {
                // make sure it really is a port, and has a number after the :
                if ( temp[portIndex+1] >= '0' && temp[portIndex+1] <= '9' )
                {
                    int tempIndex = temp.IndexOf( '/', Rindex);

                    if (tempIndex == -1)
                    {
                        m_port = Int32.Parse( temp.Substring(portIndex + 1), CultureInfo.InvariantCulture );

                        if (m_port < 0)
                            throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidUrl" ) );

                        temp = temp.Substring( Rindex, portIndex - Rindex );
                    }
                    else if (tempIndex > portIndex)
                    {
                        m_port = Int32.Parse( temp.Substring(portIndex + 1, tempIndex - portIndex - 1), CultureInfo.InvariantCulture );
                        temp = temp.Substring( Rindex, portIndex - Rindex ) + temp.Substring( tempIndex );
                    }
                    else 
                        throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidUrl" ) );                            
                }
                else
                    throw new ArgumentException( Environment.GetResourceString( "Argument_InvalidUrl" ) );
            }
            else {
                // Chop of the user/pass portion if any
                temp = temp.Substring(Rindex);
            }
                
            return temp;
        }