Beispiel #1
0
        bool ComputeRelativeSegmentsAndLookup(Uri uri,
                                              ICollection <string> relativePathSegments,               // add to this
                                              ICollection <UriTemplateTableMatchCandidate> candidates) // matched candidates
        {
            string[] uriSegments         = uri.Segments;
            int      numRelativeSegments = uriSegments.Length - this.numSegmentsInBaseAddress;

            Fx.Assert(numRelativeSegments >= 0, "bad num segments");
            UriTemplateLiteralPathSegment[] uSegments = new UriTemplateLiteralPathSegment[numRelativeSegments];
            for (int i = 0; i < numRelativeSegments; ++i)
            {
                string seg = uriSegments[i + this.numSegmentsInBaseAddress];
                // compute representation for matching
                UriTemplateLiteralPathSegment lps = UriTemplateLiteralPathSegment.CreateFromWireData(seg);
                uSegments[i] = lps;
                // compute representation to project out into results
                string relPathSeg = Uri.UnescapeDataString(seg);
                if (lps.EndsWithSlash)
                {
                    Fx.Assert(relPathSeg.EndsWith("/", StringComparison.Ordinal), "problem with relative path segment");
                    relPathSeg = relPathSeg.Substring(0, relPathSeg.Length - 1); // trim slash
                }
                relativePathSegments.Add(relPathSeg);
            }
            return(rootNode.Match(uSegments, candidates));
        }
        private bool ComputeRelativeSegmentsAndLookup(Uri uri, ICollection <string> relativePathSegments, ICollection <UriTemplateTableMatchCandidate> candidates)
        {
            string[] segments = uri.Segments;
            int      num      = segments.Length - this.numSegmentsInBaseAddress;

            UriTemplateLiteralPathSegment[] wireData = new UriTemplateLiteralPathSegment[num];
            for (int i = 0; i < num; i++)
            {
                string str = segments[i + this.numSegmentsInBaseAddress];
                UriTemplateLiteralPathSegment segment = UriTemplateLiteralPathSegment.CreateFromWireData(str);
                wireData[i] = segment;
                string item = Uri.UnescapeDataString(str);
                if (segment.EndsWithSlash)
                {
                    item = item.Substring(0, item.Length - 1);
                }
                relativePathSegments.Add(item);
            }
            return(this.rootNode.Match(wireData, candidates));
        }