示例#1
0
        internal static ReadOnlySpan <byte> SliceTo(this ReadOnlySpan <byte> buffer, int start, byte terminator, out int consumedBytes)
        {
            var slice = buffer.Slice(start);
            var index = ReadOnlySpanExtensions.IndexOf(slice, terminator);

            if (index == -1)
            {
                consumedBytes = 0;
                return(Span <byte> .Empty);
            }
            consumedBytes = index;
            return(slice.Slice(0, index));
        }
示例#2
0
        internal static ReadOnlySpan <byte> SliceTo(this ReadOnlySpan <byte> buffer, int start, byte terminatorFirst, byte terminatorSecond, out int consumedBytes)
        {
            int offset = 0;

            while (true)
            {
                var slice = buffer.Slice(start + offset);
                var index = ReadOnlySpanExtensions.IndexOf(slice, terminatorFirst);
                if (index == -1 || index == slice.Length - 1)
                {
                    consumedBytes = 0;
                    return(Span <byte> .Empty);
                }
                if (slice[index + 1] == terminatorSecond)
                {
                    consumedBytes = index;
                    return(slice.Slice(0, index + offset));
                }
                else
                {
                    offset += index;
                }
            }
        }