| | | 1 | | /******************************************************************************** |
| | | 2 | | * LiteralSegmentDefinition.cs * |
| | | 3 | | * * |
| | | 4 | | * Author: Denes Solti * |
| | | 5 | | ********************************************************************************/ |
| | | 6 | | using System; |
| | | 7 | | using System.Runtime.CompilerServices; |
| | | 8 | | using System.Text.RegularExpressions; |
| | | 9 | | |
| | | 10 | | namespace NanoRoute.Internals |
| | | 11 | | { |
| | | 12 | | using Properties; |
| | | 13 | | |
| | | 14 | | internal static class LiteralSegmentDefinition |
| | | 15 | | { |
| | | 16 | | private const string |
| | | 17 | | URI_CHAR = @"[\w.\-~+]", |
| | | 18 | | PERCENT_ENCODED_CHAR = "%[0-9A-Fa-f]{2}", |
| | | 19 | | LITERAL_SEGMENT_PATTERN = $@"\G(?:{URI_CHAR}|{PERCENT_ENCODED_CHAR})+"; |
| | | 20 | | |
| | 2 | 21 | | private static readonly Regex s_literalSegment = new(LITERAL_SEGMENT_PATTERN, RuntimeFeature.IsDynamicCodeSuppor |
| | | 22 | | |
| | | 23 | | public static ReadOnlyMemory<char> Parse(string pattern, ref int offset) |
| | 2 | 24 | | { |
| | 2 | 25 | | if (s_literalSegment.Match(pattern, offset) is not { Success: true, Length: int length }) |
| | 1 | 26 | | throw new InvalidOperationException(string.Format(Resources.Culture, Resources.ERR_INVALID_PATTERN, offs |
| | | 27 | | |
| | 2 | 28 | | ReadOnlyMemory<char> segment = UrlUtils.DecodeUrl(pattern.AsMemory(offset, length), UrlDecodeMode.Path); |
| | | 29 | | |
| | 2 | 30 | | offset += length - 1; |
| | 2 | 31 | | return segment; |
| | 2 | 32 | | } |
| | | 33 | | } |
| | | 34 | | } |