< Summary

Information
Class: NanoRoute.Internals.DelimitedSegment
Assembly: NanoRoute.dll
File(s): /home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Private/LowLevel/DelimitedSegment.cs
Line coverage
100%
Covered lines: 42
Uncovered lines: 0
Coverable lines: 42
Total lines: 86
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

File(s)

/home/runner/work/nanoroute/nanoroute/Src/NanoRoute/Private/LowLevel/DelimitedSegment.cs

#LineLine coverage
 1/********************************************************************************
 2* DelimitedSegment.cs                                                           *
 3*                                                                               *
 4* Author: Denes Solti                                                           *
 5********************************************************************************/
 6using System;
 7using System.Collections;
 8using System.Collections.Generic;
 9
 10namespace NanoRoute.Internals
 11{
 12    internal struct DelimitedSegment(ReadOnlyMemory<char> original, char separator) : IEnumerator<ReadOnlyMemory<char>>
 13    {
 14        private const int DONE = -1;
 15
 16        private int _next;
 17
 18        public bool MoveNext()
 219        {
 220            if (_next is DONE)
 221            {
 222                Current = default;
 223                return false;
 24            }
 25
 226            ReadOnlySpan<char> span = Original.Span;
 27
 228            while (_next < span.Length && span[_next] == Separator)
 229                _next++;
 30
 231            if (_next >= span.Length)
 132            {
 133                Current = default;
 134                _next = DONE;
 135                return false;
 36            }
 37
 238            int i = span.Slice(_next).IndexOf(Separator);
 239            if (i < 0)
 240            {
 241                Current = Original.Slice(_next);
 242                _next = DONE;
 243            }
 44            else
 145            {
 146                Current = Original.Slice(_next, i);
 147                _next += i + 1;
 148            }
 49
 250            return true;
 251        }
 52
 53        public void Reset()
 154        {
 155            _next = 0;
 156            Current = default;
 157        }
 58
 159        public readonly void Dispose() { }
 60
 61        public ReadOnlyMemory<char> Current { get; private set; }
 62
 163        readonly object IEnumerator.Current => Current;
 64
 65        public readonly ReadOnlyMemory<char> Remaining
 66        {
 67            get
 268            {
 269                if (!HasValue)
 270                    return _next > DONE ? Original.Slice(Math.Max(0, _next - 1)) : default;
 71
 172                int segmentStart = _next is DONE
 173                    ? Original.Length - Current.Length
 174                    : _next - Current.Length - 1;
 75
 176                return Original.Slice(Math.Max(0, segmentStart - 1));
 277            }
 78        }
 79
 280        public ReadOnlyMemory<char> Original { get; } = original;
 81
 282        public char Separator { get; } = separator;
 83
 284        public readonly bool HasValue => Current.Length > 0;
 85    }
 86}