Fixed a bunch of clang-tidy warnings.
This commit is contained in:
@@ -75,7 +75,7 @@ StreamError Stream::writeBinaryString(std::string_view str)
|
||||
{
|
||||
MIJIN_ASSERT(str.length() <= std::numeric_limits<std::uint32_t>::max(), "Binary string is too long.");
|
||||
const std::uint32_t length = static_cast<std::uint32_t>(str.length());
|
||||
StreamError error = write(length);
|
||||
const StreamError error = write(length);
|
||||
if (error != StreamError::SUCCESS) {
|
||||
return error;
|
||||
}
|
||||
@@ -118,12 +118,12 @@ StreamError Stream::getTotalLength(std::size_t& outLength)
|
||||
return StreamError::NOT_SUPPORTED;
|
||||
}
|
||||
const std::size_t origPos = tell();
|
||||
if (StreamError error = seek(0, SeekMode::RELATIVE_TO_END); error != StreamError::SUCCESS)
|
||||
if (const StreamError error = seek(0, SeekMode::RELATIVE_TO_END); error != StreamError::SUCCESS)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
outLength = tell();
|
||||
if (StreamError error = seek(static_cast<std::intptr_t>(origPos)); error != StreamError::SUCCESS)
|
||||
if (const StreamError error = seek(static_cast<std::intptr_t>(origPos)); error != StreamError::SUCCESS)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
@@ -134,12 +134,12 @@ StreamError Stream::readRest(TypelessBuffer& outBuffer)
|
||||
{
|
||||
// first try to allocate everything at once
|
||||
std::size_t length = 0;
|
||||
if (StreamError lengthError = getTotalLength(length); lengthError == StreamError::SUCCESS)
|
||||
if (const StreamError lengthError = getTotalLength(length); lengthError == StreamError::SUCCESS)
|
||||
{
|
||||
MIJIN_ASSERT(getFeatures().tell, "How did you find the length if you cannot tell()?");
|
||||
length -= tell();
|
||||
outBuffer.resize(length);
|
||||
if (StreamError error = readRaw(outBuffer.data(), length); error != StreamError::SUCCESS)
|
||||
if (const StreamError error = readRaw(outBuffer.data(), length); error != StreamError::SUCCESS)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
@@ -153,13 +153,13 @@ StreamError Stream::readRest(TypelessBuffer& outBuffer)
|
||||
while (!isAtEnd())
|
||||
{
|
||||
std::size_t bytesRead = 0;
|
||||
if (StreamError error = readRaw(chunk, {.partial = true}, &bytesRead); error != StreamError::SUCCESS)
|
||||
if (const StreamError error = readRaw(chunk, {.partial = true}, &bytesRead); error != StreamError::SUCCESS)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
outBuffer.resize(outBuffer.byteSize() + bytesRead);
|
||||
std::span<std::byte> bufferBytes = outBuffer.makeSpan<std::byte>();
|
||||
const std::span<std::byte> bufferBytes = outBuffer.makeSpan<std::byte>();
|
||||
std::copy_n(chunk.begin(), bytesRead, bufferBytes.end() - static_cast<long>(bytesRead));
|
||||
}
|
||||
return StreamError::SUCCESS;
|
||||
@@ -213,14 +213,14 @@ StreamError Stream::readLine(std::string& outString)
|
||||
{
|
||||
// read into the buffer
|
||||
std::size_t bytesRead = 0;
|
||||
if (StreamError error = readRaw(buffer, {.partial = true, .peek = true}, &bytesRead); error != StreamError::SUCCESS)
|
||||
if (const StreamError error = readRaw(buffer, {.partial = true, .peek = true}, &bytesRead); error != StreamError::SUCCESS)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
// try to find a \n
|
||||
auto begin = buffer.begin();
|
||||
auto end = buffer.begin() + bytesRead;
|
||||
auto newline = std::find(begin, end, '\n');
|
||||
auto begin = buffer.begin(); // NOLINT(readability-qualified-auto)
|
||||
auto end = buffer.begin() + bytesRead; // NOLINT(readability-qualified-auto)
|
||||
auto newline = std::find(begin, end, '\n'); // NOLINT(readability-qualified-auto)
|
||||
|
||||
if (newline != end)
|
||||
{
|
||||
@@ -235,7 +235,7 @@ StreamError Stream::readLine(std::string& outString)
|
||||
}
|
||||
|
||||
// read again, this time to skip
|
||||
if (StreamError error = readSpan(begin, end); error != StreamError::SUCCESS)
|
||||
if (const StreamError error = readSpan(begin, end); error != StreamError::SUCCESS)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
@@ -262,9 +262,9 @@ mijin::Task<StreamError> Stream::c_readLine(std::string& outString)
|
||||
co_return error;
|
||||
}
|
||||
// try to find a \n
|
||||
auto begin = buffer.begin();
|
||||
auto end = buffer.begin() + bytesRead;
|
||||
auto newline = std::find(begin, end, '\n');
|
||||
auto begin = buffer.begin(); // NOLINT(readability-qualified-auto)
|
||||
auto end = buffer.begin() + bytesRead; // NOLINT(readability-qualified-auto)
|
||||
auto newline = std::find(begin, end, '\n'); // NOLINT(readability-qualified-auto)
|
||||
|
||||
if (newline != end)
|
||||
{
|
||||
@@ -359,7 +359,7 @@ StreamError FileStream::readRaw(std::span<std::uint8_t> buffer, const ReadOption
|
||||
}
|
||||
if (options.peek)
|
||||
{
|
||||
if (StreamError error = seek(-static_cast<std::intptr_t>(readBytes), SeekMode::RELATIVE); error != StreamError::SUCCESS)
|
||||
if (const StreamError error = seek(-static_cast<std::intptr_t>(readBytes), SeekMode::RELATIVE); error != StreamError::SUCCESS)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user