< Summary

Information
Class: NanoRoute.Internals.LiteralSegmentDefinition
Assembly: NanoRoute.dll
File(s): /home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Private/RoutePattern/LiteralSegmentDefinition.cs
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 34
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBlocks covered Blocks not covered
LiteralSegmentDefinition()51
Parse(...)170

File(s)

/home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Private/RoutePattern/LiteralSegmentDefinition.cs

#LineLine coverage
 1/********************************************************************************
 2* LiteralSegmentDefinition.cs                                                   *
 3*                                                                               *
 4* Author: Denes Solti                                                           *
 5********************************************************************************/
 6using System;
 7using System.Runtime.CompilerServices;
 8using System.Text.RegularExpressions;
 9
 10namespace 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
 221        private static readonly Regex s_literalSegment = new(LITERAL_SEGMENT_PATTERN, RuntimeFeature.IsDynamicCodeSuppor
 22
 23        public static ReadOnlyMemory<char> Parse(string pattern, ref int offset)
 224        {
 225            if (s_literalSegment.Match(pattern, offset) is not { Success: true, Length: int length })
 126                throw new InvalidOperationException(string.Format(Resources.Culture, Resources.ERR_INVALID_PATTERN, offs
 27
 228            ReadOnlyMemory<char> segment = UrlUtils.DecodeUrl(pattern.AsMemory(offset, length), UrlDecodeMode.Path);
 29
 230            offset += length - 1;
 231            return segment;
 232        }
 33    }
 34}