Reece Wilson
04aca5fcf2
[+] Aurora::IO::FS::DirDeleterEx [+] Aurora::IO::Compress [+] Aurora::IO::Decompress [*] Aurora::Memory::ByteBuffer zero-alloc fixes [*] Aurora::Memory::ByteBuffer linear read of begin/end should return (`const AuUInt8 *`)'s [*] Changed NT file CREATE flags [*] Fix linux regression [*] Update logger sink DirLogArchive ... [+] DirectoryLogger::uMaxLogsOrZeroBeforeDelete ... [+] DirectoryLogger::uMaxCumulativeFileSizeInMiBOrZeroBeforeDelete ... [+] DirectoryLogger::uMaxCumulativeFileSizeInMiBOrZeroBeforeCompress ... [+] DirectoryLogger::uMaxFileTimeInDeltaMSOrZeroBeforeCompress ... [+] DirectoryLogger::uMaxFileTimeInDeltaMSOrZeroBeforeDelete [*] FIX: BufferedLineReader was taking the wrong end head (prep) LZMACompressor [*] Updated build-script for LZMA (when i can be bothered to impl it) (prep) FSOverlappedUtilities (prep) FSDefaultOverlappedWorkerThread | default worker pool / apc dispatcher / auasync dispatcher concept for higher level overlapped ops (stub) [+] Aurora::IO::FS::OverlappedForceDelegatedIO (stub) [+] Aurora::IO::FS::OverlappedCompress (stub) [+] Aurora::IO::FS::OverlappedDecompress (stub) [+] Aurora::IO::FS::OverlappedWrite (stub) [+] Aurora::IO::FS::OverlappedRead (stub) [+] Aurora::IO::FS::OverlappedStat (stub) [+] Aurora::IO::FS::OverlappedCopy (stub) [+] Aurora::IO::FS::OverlappedRelink (stub) [+] Aurora::IO::FS::OverlappedTrustFile (stub) [+] Aurora::IO::FS::OverlappedBlockFile (stub) [+] Aurora::IO::FS::OverlappedUnblockFile (stub) [+] Aurora::IO::FS::OverlappedDelete
117 lines
3.0 KiB
C++
117 lines
3.0 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: BufferedLineReader.cpp
|
|
Date: 2022-2-8
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "BufferedLineReader.hpp"
|
|
|
|
namespace Aurora::IO::Character
|
|
{
|
|
void BufferedLineReader::Flush()
|
|
{
|
|
this->flushLine_ = true;
|
|
}
|
|
|
|
bool BufferedLineReader::ReadBytes(AuUInt32 length)
|
|
{
|
|
AU_LOCK_GUARD(this->lock_);
|
|
|
|
if (!this->buffer_.Resize(this->buffer_.GetWriteOffset() + length))
|
|
{
|
|
SysPushErrorMem();
|
|
return false;
|
|
}
|
|
|
|
AuUInt bytesRead;
|
|
if (this->inputStream_->Read(AuMemoryViewStreamWrite(AuMemoryViewWrite(this->buffer_.writePtr, this->buffer_.writePtr + this->buffer_.length), bytesRead)) !=
|
|
EStreamError::eErrorNone)
|
|
{
|
|
SysPushErrorIO();
|
|
return false;
|
|
}
|
|
|
|
this->buffer_.writePtr += bytesRead;
|
|
return true;
|
|
}
|
|
|
|
AuList<AuString> BufferedLineReader::ReadLines()
|
|
{
|
|
AU_LOCK_GUARD(this->lock_);
|
|
AuList<AuString> ret;
|
|
|
|
bool writeAll = AuExchange(this->flushLine_, false);
|
|
|
|
if (!this->buffer_)
|
|
{
|
|
return ret;
|
|
}
|
|
|
|
while (this->buffer_.readPtr < this->buffer_.writePtr)
|
|
{
|
|
Memory::ByteBufferPushReadState _(this->buffer_, true);
|
|
|
|
if (*this->buffer_.readPtr != '\n')
|
|
{
|
|
this->buffer_.readPtr++;
|
|
continue;
|
|
}
|
|
|
|
auto end = this->buffer_.GetReadOffset();
|
|
auto next = end + 1;
|
|
if (end != 0)
|
|
{
|
|
if (this->buffer_.readPtr[-1] == '\r')
|
|
{
|
|
end--;
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
if (!AuTryInsert(ret, AuString(this->buffer_.base, this->buffer_.base + end)))
|
|
{
|
|
this->buffer_.flagReadError = true;
|
|
break;
|
|
}
|
|
|
|
this->buffer_.readPtr = this->buffer_.base + next;
|
|
}
|
|
catch (...)
|
|
{
|
|
this->buffer_.flagReadError = true;
|
|
SysPushErrorCatch();
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (writeAll && this->buffer_.readPtr && this->buffer_.readPtr != this->buffer_.writePtr)
|
|
{
|
|
try
|
|
{
|
|
if (AuTryInsert(ret, AuString(this->buffer_.base, this->buffer_.base + this->buffer_.length)))
|
|
{
|
|
this->buffer_.readPtr = this->buffer_.base + this->buffer_.length;
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
SysPushErrorCatch();
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
AUKN_SYM IBufferedLineReader *NewLineReaderNew(const AuSPtr<IStreamReader> &input)
|
|
{
|
|
return _new BufferedLineReader(input);
|
|
}
|
|
|
|
AUKN_SYM void NewLineReaderNew(IBufferedLineReader *reader)
|
|
{
|
|
AuSafeDelete<BufferedLineReader *>(reader);
|
|
}
|
|
} |