| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections.Specialized; |
| | | 6 | | using System.Diagnostics; |
| | | 7 | | using System.Text; |
| | | 8 | | using CoreWCF.Runtime; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF |
| | | 11 | | { |
| | | 12 | | // This represents a Path segment, which can either be a Literal, a Variable or a Compound |
| | | 13 | | [DebuggerDisplay("Segment={OriginalSegment} Nature={Nature}}")] |
| | | 14 | | internal abstract class UriTemplatePathSegment |
| | | 15 | | { |
| | 706 | 16 | | protected UriTemplatePathSegment(string originalSegment, UriTemplatePartType nature, |
| | 706 | 17 | | bool endsWithSlash) |
| | | 18 | | { |
| | 706 | 19 | | OriginalSegment = originalSegment; |
| | 706 | 20 | | Nature = nature; |
| | 706 | 21 | | EndsWithSlash = endsWithSlash; |
| | 706 | 22 | | } |
| | | 23 | | |
| | 1836 | 24 | | public bool EndsWithSlash { get; } |
| | | 25 | | |
| | 553 | 26 | | public UriTemplatePartType Nature { get; } |
| | | 27 | | |
| | 0 | 28 | | public string OriginalSegment { get; } |
| | | 29 | | |
| | | 30 | | public static UriTemplatePathSegment CreateFromUriTemplate(string segment, UriTemplate template) |
| | | 31 | | { |
| | | 32 | | // Identifying the type of segment - Literal|Compound|Variable |
| | 576 | 33 | | switch (UriTemplateHelpers.IdentifyPartType(segment)) |
| | | 34 | | { |
| | | 35 | | case UriTemplatePartType.Literal: |
| | 500 | 36 | | return UriTemplateLiteralPathSegment.CreateFromUriTemplate(segment, template); |
| | | 37 | | |
| | | 38 | | case UriTemplatePartType.Compound: |
| | 24 | 39 | | return UriTemplateCompoundPathSegment.CreateFromUriTemplate(segment, template); |
| | | 40 | | |
| | | 41 | | case UriTemplatePartType.Variable: |
| | 52 | 42 | | if (segment.EndsWith("/", StringComparison.Ordinal)) |
| | | 43 | | { |
| | 2 | 44 | | string varName = template.AddPathVariable(UriTemplatePartType.Variable, |
| | 2 | 45 | | segment.Substring(1, segment.Length - 3)); |
| | 2 | 46 | | return new UriTemplateVariablePathSegment(segment, true, varName); |
| | | 47 | | } |
| | | 48 | | else |
| | | 49 | | { |
| | 50 | 50 | | string varName = template.AddPathVariable(UriTemplatePartType.Variable, |
| | 50 | 51 | | segment.Substring(1, segment.Length - 2)); |
| | 50 | 52 | | return new UriTemplateVariablePathSegment(segment, false, varName); |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | default: |
| | | 56 | | Fx.Assert("Invalid value from IdentifyStringNature"); |
| | 0 | 57 | | return null; |
| | | 58 | | } |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | public abstract void Bind(string[] values, ref int valueIndex, StringBuilder path); |
| | | 62 | | |
| | | 63 | | public abstract bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash); |
| | | 64 | | |
| | 1 | 65 | | public bool IsMatch(UriTemplateLiteralPathSegment segment) => IsMatch(segment, false); |
| | | 66 | | |
| | | 67 | | public abstract bool IsMatch(UriTemplateLiteralPathSegment segment, bool ignoreTrailingSlash); |
| | | 68 | | |
| | | 69 | | public abstract void Lookup(string segment, NameValueCollection boundParameters); |
| | | 70 | | } |
| | | 71 | | } |