Esempio n. 1
0
        public string String_Create(PathString pathBaseString, PathString pathString, QueryString queryString, FragmentString fragmentString)
        {
            var pathBase = pathBaseString.ToUriComponent();
            var path     = pathString.ToUriComponent();
            var query    = queryString.ToUriComponent();
            var fragment = fragmentString.ToUriComponent();

            var length = pathBase.Length + path.Length + query.Length + fragment.Length;

            if (string.IsNullOrEmpty(pathBase) && string.IsNullOrEmpty(path))
            {
                if (length == 0)
                {
                    return("/");
                }

                path = "/";
                length++;
            }
            else
            {
                if (!string.IsNullOrEmpty(pathBase) && pathBase.Length == length)
                {
                    return(pathBase);
                }

                if (path.Length == length)
                {
                    return(path);
                }
            }

            return(string.Create(length, (pathBase, path, query, fragment), initializeStringSpanAction));
        }
Esempio n. 2
0
        public string String_Create(HostString hostString, PathString pathBaseString, PathString pathString, QueryString queryString, FragmentString fragmentString)
        {
            var scheme   = "https";
            var host     = hostString.ToUriComponent();
            var pathBase = pathBaseString.ToUriComponent();
            var path     = pathString.ToUriComponent();
            var query    = queryString.ToUriComponent();
            var fragment = fragmentString.ToUriComponent();

            // PERF: Calculate string length to allocate correct buffer size for string.Create.
            var length =
                scheme.Length +
                Uri.SchemeDelimiter.Length +
                host.Length +
                pathBase.Length +
                path.Length +
                query.Length +
                fragment.Length;

            if (string.IsNullOrEmpty(pathBase) && string.IsNullOrEmpty(path))
            {
                path = "/";
                length++;
            }

            return(string.Create(length, (scheme, host, pathBase, path, query, fragment), initializeStringSpanAction));
        }
Esempio n. 3
0
 public string Single_Concat(PathString pathBase, PathString path, QueryString query, FragmentString fragment)
 {
     if (pathBase.HasValue || path.HasValue)
     {
         return(pathBase.ToUriComponent() + path.ToUriComponent() + query.ToUriComponent() + fragment.ToUriComponent());
     }
     else
     {
         return("/" + query.ToUriComponent() + fragment.ToUriComponent());
     }
 }
Esempio n. 4
0
        public string StringBuilder_WithoutCombinedPathGeneration(HostString host, PathString pathBase, PathString path, QueryString query, FragmentString fragment)
        {
            var scheme          = "https";
            var SchemeDelimiter = Uri.SchemeDelimiter;

            var encodedHost     = host.ToUriComponent();
            var encodedPathBase = pathBase.ToUriComponent();
            var encodedPath     = path.ToUriComponent();
            var encodedQuery    = query.ToUriComponent();
            var encodedFragment = fragment.ToUriComponent();

            // PERF: Calculate string length to allocate correct buffer size for StringBuilder.
            var length =
                scheme.Length +
                SchemeDelimiter.Length +
                encodedHost.Length +
                encodedPathBase.Length +
                encodedPath.Length +
                encodedQuery.Length +
                encodedFragment.Length;

            if (!pathBase.HasValue && !path.HasValue)
            {
                length++;
            }

            var builder = new StringBuilder(length)
                          .Append(scheme)
                          .Append(SchemeDelimiter)
                          .Append(encodedHost);

            if (!pathBase.HasValue && !path.HasValue)
            {
                builder.Append('/');
            }
            else
            {
                builder
                .Append(encodedPathBase)
                .Append(encodedPath);
            }

            return(builder
                   .Append(encodedQuery)
                   .Append(encodedFragment)
                   .ToString());
        }
Esempio n. 5
0
        public string String_Concat_WithArrayArgument(HostString host, PathString pathBase, PathString path, QueryString query, FragmentString fragment)
        {
            var scheme          = "https";
            var SchemeDelimiter = Uri.SchemeDelimiter;

            if (!pathBase.HasValue && !path.HasValue)
            {
                return(scheme + SchemeDelimiter + "/" + host.ToUriComponent() + "/" + query.ToUriComponent() + fragment.ToUriComponent());
            }
            else
            {
                return(scheme + SchemeDelimiter + pathBase.ToUriComponent() + path.ToUriComponent() + host.ToUriComponent() + "/" + query.ToUriComponent() + fragment.ToUriComponent());
            }
        }