Ejemplo n.º 1
0
        /// <summary>
        /// The url has been read to here. Remember the url if its valid, and reset state.
        /// </summary>
        /// <param name="state">The state indicating if this url is valid. If its valid it will be added to the list of urls.</param>
        /// <returns>True if the url was valid</returns>
        private bool ReadEnd(ReadEndState state)
        {
            //if the url is valid and greater then 0
            if (state == ReadEndState.ValidUrl && _buffer.Length > 0)
            {
                //get the last character. if its a quote, cut it off.
                var len        = _buffer.Length;
                var startIndex = len - 1;
                if (_quoteStart && _buffer[startIndex] == '\"')
                {
                    _buffer.Remove(startIndex, len - startIndex);
                }

                //Add the url to the list of good urls.
                if (_buffer.Length > 0)
                {
                    _currentUrlMarker.SetOriginalUrl(_buffer.ToString());
                    _urlList.Add(_currentUrlMarker.CreateUrl());
                }
            }

            //clear out the buffer.
            _buffer.Remove(0, _buffer.Length);

            //reset the state of internal objects.
            _quoteStart       = false;
            _hasScheme        = false;
            _dontMatchIpv6    = false;
            _currentUrlMarker = new UrlMarker();

            //return true if valid.
            return(state == ReadEndState.ValidUrl);
        }
Ejemplo n.º 2
0
        public void TestUrlMarkers(string testString, string scheme, string username, string password, string host, int port,
                                   string path, string query, string fragment, int[] indices)
        {
            var urlMarker = new UrlMarker();

            urlMarker.SetOriginalUrl(testString);
            urlMarker.SetIndices(indices);
            var url = urlMarker.CreateUrl();

            Assert.Equal(url.GetHost(), host /*, "host, " + testString*/);
            Assert.Equal(url.GetPath(), path /*, "path, " + testString*/);
            Assert.Equal(url.GetScheme(), scheme /*, "scheme, " + testString*/);
            Assert.Equal(url.GetUsername(), username /*, "username, " + testString*/);
            Assert.Equal(url.GetPassword(), password /*, "password, " + testString*/);
            Assert.Equal(url.GetPort(), port /*, "port, " + testString*/);
            Assert.Equal(url.GetQuery(), query /*, "query, " + testString*/);
            Assert.Equal(url.GetFragment(), fragment /*, "fragment, " + testString*/);
        }