Example #1
0
        public string ReadUtf8LineStrict(long limit)
        {
            if (limit < 0)
            {
                throw new ArgumentException("limit < 0: " + limit);
            }
            long scanLength = limit == long.MaxValue ? long.MaxValue : limit + 1;
            long newline    = IndexOf((byte)'\n', 0, scanLength);

            if (newline != -1)
            {
                return(_easyBuffer.ReadUtf8Line(newline));
            }
            if (scanLength < long.MaxValue &&
                Request(scanLength) && _easyBuffer.GetByte(scanLength - 1) == '\r' &&
                Request(scanLength + 1) && _easyBuffer.GetByte(scanLength) == '\n')
            {
                return(_easyBuffer.ReadUtf8Line(scanLength)); // The line was 'limit' UTF-8 bytes followed by \r\n.
            }
            var data = new EasyBuffer();

            _easyBuffer.CopyTo(data, 0, Math.Min(32, _easyBuffer.Size));
            throw new IndexOutOfRangeException("\\n not found: limit=" + Math.Min(_easyBuffer.Size, limit)
                                               + " content=" + data.ReadByteString().Hex() + '…');
        }