Esempio n. 1
0
 private Url(string scheme, string host, string port)
 {
     Data      = string.Empty;
     _path     = string.Empty;
     _scheme   = scheme;
     _host     = host;
     _port     = port;
     _relative = ProtocolNames.IsRelative(_scheme);
 }
Esempio n. 2
0
 private void Reset(Url baseUrl)
 {
     Data      = string.Empty;
     _scheme   = baseUrl._scheme;
     _host     = baseUrl._host;
     _path     = baseUrl._path;
     _port     = baseUrl._port;
     _relative = ProtocolNames.IsRelative(_scheme);
 }
Esempio n. 3
0
        private bool ParseScheme(string input, bool onlyScheme = false)
        {
            if ((input.Length <= 0) || !input[0].IsLetter())
            {
                return(!onlyScheme && RelativeState(input, 0));
            }

            var index = 1;

            while (index < input.Length)
            {
                var c = input[index];

                if (c.IsAlphanumericAscii() || (c == Symbols.Plus) || (c == Symbols.Minus) || (c == Symbols.Dot))
                {
                    index++;
                }
                else if (c == Symbols.Colon)
                {
                    var originalScheme = _scheme;
                    _scheme = input.Substring(0, index).ToLowerInvariant();

                    if (!onlyScheme)
                    {
                        _relative = ProtocolNames.IsRelative(_scheme);

                        if (_scheme.Is(ProtocolNames.File))
                        {
                            _host = string.Empty;
                            _port = string.Empty;
                            return(RelativeState(input, index + 1));
                        }
                        if (!_relative)
                        {
                            _host = string.Empty;
                            _port = string.Empty;
                            _path = string.Empty;
                            return(ParseSchemeData(input, index + 1));
                        }
                        if (_scheme.Is(originalScheme))
                        {
                            c = input[++index];

                            if ((c == Symbols.Solidus) && (index + 2 < input.Length) &&
                                (input[index + 1] == Symbols.Solidus))
                            {
                                return(IgnoreSlashesState(input, index + 2));
                            }

                            return(RelativeState(input, index));
                        }

                        if ((index < input.Length - 1) && (input[++index] == Symbols.Solidus) &&
                            (++index < input.Length) && (input[index] == Symbols.Solidus))
                        {
                            index++;
                        }

                        return(IgnoreSlashesState(input, index));
                    }

                    return(true);
                }
                else
                {
                    break;
                }
            }

            return(!onlyScheme && RelativeState(input, 0));
        }