diff options
Diffstat (limited to 'source/fud_string.cpp')
-rw-r--r-- | source/fud_string.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/source/fud_string.cpp b/source/fud_string.cpp index 2a17201..37a2a4b 100644 --- a/source/fud_string.cpp +++ b/source/fud_string.cpp @@ -19,12 +19,11 @@ #include "fud_assert.hpp" -#include <type_traits> - namespace fud { StringResult String::makeFromCString(const char8_t* cString) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) return makeFromCString(reinterpret_cast<const char*>(cString)); } @@ -35,6 +34,7 @@ StringResult String::makeFromCString(const char* cString) StringResult String::makeFromCString(const char8_t* cString, Allocator* allocator) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) return makeFromCString(reinterpret_cast<const char*>(cString), allocator); } @@ -61,6 +61,7 @@ StringResult String::makeFromCString(const char* cString, Allocator* allocator) } String output{}; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) output.m_allocator = reinterpret_cast<uintptr_t>(allocator); utf8* outputData{nullptr}; @@ -86,6 +87,7 @@ StringResult String::makeFromCString(const char* cString, Allocator* allocator) return StringResult::okay(std::move(output)); } +//NOLINTNEXTLINE(performance-unnecessary-value-param) StringResult String::from(const String& rhs, Option<Allocator*> allocatorOption) { if (!rhs.valid()) { @@ -98,10 +100,11 @@ StringResult String::from(const String& rhs, Option<Allocator*> allocatorOption) } String output{}; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) output.m_allocator = reinterpret_cast<uintptr_t>(allocator); utf8* outputData{nullptr}; - size_t outputCapacity{0}; - size_t outputLength{0}; + size_t outputCapacity{rhs.capacity()}; + size_t outputLength{rhs.length()}; if (rhs.isLarge()) { auto status = output.makeLarge(outputCapacity, outputLength, outputData); if (status != FudStatus::Success) { @@ -132,6 +135,7 @@ StringResult String::from(StringView view, Allocator* allocator) } String output{}; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) output.m_allocator = reinterpret_cast<uintptr_t>(allocator); size_t outputCapacity = view.length() + 1U; bool isLarge = outputCapacity > SsoBufSize; @@ -154,7 +158,7 @@ StringResult String::from(StringView view, Allocator* allocator) return StringResult::okay(std::move(output)); } -String::String(String&& rhs) noexcept : m_allocator{rhs.m_allocator}, m_repr{std::move(rhs.m_repr)} +String::String(String&& rhs) noexcept : m_allocator{rhs.m_allocator}, m_repr{rhs.m_repr} { rhs.setSmall(); rhs.m_repr.small.length = 0; @@ -189,6 +193,7 @@ FudStatus String::copy(const String& rhs) if (allocResult.isError()) { return allocResult.takeError(); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) m_repr.large.data = reinterpret_cast<utf8*>(allocResult.takeOkay()); outputCapacity = m_repr.large.capacity; outputLength = m_repr.large.length; @@ -219,7 +224,7 @@ String& String::operator=(String&& rhs) noexcept cleanup(); m_allocator = rhs.m_allocator; - m_repr = std::move(rhs.m_repr); + m_repr = rhs.m_repr; if (isLarge()) { rhs.m_repr.large.data = nullptr; @@ -232,6 +237,7 @@ void String::cleanup() { const auto* allocPtr = allocator(); if (isLarge() && m_repr.large.data != nullptr && allocPtr != nullptr) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) allocator()->deallocate(reinterpret_cast<std::byte*>(m_repr.large.data), m_repr.large.capacity); m_repr.large.data = nullptr; } @@ -259,6 +265,7 @@ FudStatus String::resize(size_t newCapacity) auto copyResult = copyMem(dataMut(), temp.size(), temp.data(), len); fudAssert(copyResult == FudStatus::Success); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) allocator()->deallocate(reinterpret_cast<std::byte*>(m_repr.large.data), m_repr.large.capacity); setSmall(); m_repr.small.length = len & smallStringLengthMask; @@ -272,6 +279,7 @@ FudStatus String::resize(size_t newCapacity) if (allocResult.isError()) { return allocResult.takeError(); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) auto* newData = reinterpret_cast<utf8*>(allocResult.takeOkay()); fudAssert(newData != nullptr); @@ -279,6 +287,7 @@ FudStatus String::resize(size_t newCapacity) fudAssert(copyResult == FudStatus::Success); if (isLarge()) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) allocator()->deallocate(reinterpret_cast<std::byte*>(m_repr.large.data), m_repr.large.capacity); } @@ -658,7 +667,7 @@ StringResult String::catenate(const char* rhs) const if (lenResult < 0 || lenResult >= static_cast<ssize_t>(maxStringLength)) { return StringResult::error(FudStatus::ArgumentInvalid); } - size_t rhsLength = static_cast<size_t>(lenResult); + auto rhsLength = static_cast<size_t>(lenResult); if (maxStringLength - length() < rhsLength) { return StringResult::error(FudStatus::Failure); @@ -804,6 +813,7 @@ FudStatus String::makeLarge(size_t cap, size_t len, utf8*& outputData) if (dataResult.isError()) { return dataResult.getError(); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) m_repr.large.data = reinterpret_cast<utf8*>(dataResult.getOkay()); outputData = m_repr.large.data; setLarge(); |