Example #1
0
        public static bool TryReadUntill <TSequence>(ref BufferReader <TSequence> reader, out ReadOnlyBuffer <byte> bytes, ReadOnlySpan <byte> delimiter)
            where TSequence : ISequence <ReadOnlyMemory <byte> >, ISlicable
        {
            if (delimiter.Length == 0)
            {
                bytes = default;
                return(true);
            }

            int matched = 0;
            var copy    = reader;
            var start   = reader.Position;
            var end     = reader.Position;

            while (!reader.End)
            {
                if (reader.Read() == delimiter[matched])
                {
                    matched++;
                }
                else
                {
                    end     = reader.Position;
                    matched = 0;
                }
                if (matched >= delimiter.Length)
                {
                    bytes = reader.Sequence.Slice(start, end);
                    return(true);
                }
            }
            reader = copy;
            bytes  = default;
            return(false);
        }
Example #2
0
        public static bool TryReadUntill <TSequence>(ref BufferReader <TSequence> reader, out ReadOnlyBuffer <byte> bytes, byte delimiter)
            where TSequence : ISequence <ReadOnlyMemory <byte> >, ISlicable
        {
            var copy  = reader;
            var start = reader.Position;

            while (!reader.End)
            {
                SequencePosition end = reader.Position;
                if (reader.Read() == delimiter)
                {
                    bytes = reader.Sequence.Slice(start, end);
                    return(true);
                }
            }
            reader = copy;
            bytes  = default;
            return(false);
        }