public (bool success, ReadOnlyMemory <char> error) TryParseAuthority(ReadOnlySpan <char> uri, out int authorityEndIndex, ref UriInfo uriInfo)
 {
     authorityEndIndex = -1;
     if (!TryFindFirstOccurenceOf(uri, AuthorityDelimiterToken, out var authorityStartIndex))
     {
         return(false, default);
Esempio n. 2
0
        //assuming restOfUri is a slice of the URI after authority
        public (bool success, ReadOnlyMemory <char> error, ReadOnlyMemory <char> pathAsMemory) TryParsePath(ReadOnlyMemory <char> uri, int authorityEndIndex, out int pathEndIndex, ref UriInfo uriInfo)
        {
            var restOfUri = uri.Slice(authorityEndIndex);
            ReadOnlyMemory <char> pathSlice;

            if (TryFindFirstOccurenceOf(restOfUri, QueryDelimiter, out pathEndIndex) ||
                TryFindFirstOccurenceOf(restOfUri, FragmentDelimiter, out pathEndIndex))
            {
                pathSlice = restOfUri.Slice(PathSeparatorToken.Length, pathEndIndex - 1); //both query delimiter and fragment delimiter have size = 1
            }
            else
            {
                pathSlice = restOfUri.Slice(PathSeparatorToken.Length);
            }

            if (!pathSlice.IsEmpty && pathSlice.Span[^ 1] == PathSeparatorToken[0]) //ensure there is no trailing slashes
            {
                pathSlice = pathSlice[0..^ 1];