diff options
Diffstat (limited to 'source/fud_string.cpp')
-rw-r--r-- | source/fud_string.cpp | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/source/fud_string.cpp b/source/fud_string.cpp index 69df7e4..777212d 100644 --- a/source/fud_string.cpp +++ b/source/fud_string.cpp @@ -23,21 +23,18 @@ namespace fud { StringResult String::withAllocator(Allocator& allocator) { - if (!String::allocatorValid(&allocator)) - { + if (!String::allocatorValid(&allocator)) { return Error{FudStatus::ArgumentInvalid}; } String output{}; - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - output.m_allocator = reinterpret_cast<uintptr_t>(&allocator); + output.m_allocator = std::bit_cast<uintptr_t>(&allocator); return Okay{std::move(output)}; } StringResult String::makeFromCString(const char8_t* cString) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - return makeFromCString(reinterpret_cast<const char*>(cString)); + return makeFromCString(std::bit_cast<const char*>(cString)); } StringResult String::makeFromCString(const char* cString) @@ -47,8 +44,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); + return makeFromCString(std::bit_cast<const char*>(cString), allocator); } StringResult String::makeFromCString(const char* cString, Allocator* allocator) @@ -74,8 +70,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); + output.m_allocator = std::bit_cast<uintptr_t>(allocator); utf8* outputData{nullptr}; size_t outputCapacity = outputLength + 1; @@ -97,10 +92,10 @@ StringResult String::makeFromCString(const char* cString, Allocator* allocator) auto terminateStatus = output.nullTerminate(); fudAssert(terminateStatus == FudStatus::Success); - return StringResult::okay(std::move(output)); + return Okay{std::move(output)}; } -//NOLINTNEXTLINE(performance-unnecessary-value-param) +// NOLINTNEXTLINE(performance-unnecessary-value-param) StringResult String::from(const String& rhs, Option<Allocator*> allocatorOption) { if (!rhs.valid()) { @@ -113,8 +108,8 @@ 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); + output.m_allocator = std::bit_cast<uintptr_t>(allocator); + utf8* outputData{nullptr}; size_t outputCapacity{rhs.capacity()}; size_t outputLength{rhs.length()}; @@ -148,8 +143,7 @@ StringResult String::from(StringView view, Allocator* allocator) } String output{}; - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - output.m_allocator = reinterpret_cast<uintptr_t>(allocator); + output.m_allocator = std::bit_cast<uintptr_t>(allocator); size_t outputCapacity = view.length() + 1U; bool isLarge = outputCapacity > SsoBufSize; utf8* data{nullptr}; @@ -206,8 +200,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()); + m_repr.large.data = std::bit_cast<utf8*>(allocResult.takeOkay()); outputCapacity = m_repr.large.capacity; outputLength = m_repr.large.length; outputData = m_repr.large.data; @@ -250,8 +243,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); + allocator()->deallocate(std::bit_cast<std::byte*>(m_repr.large.data), m_repr.large.capacity); m_repr.large.data = nullptr; } } @@ -278,8 +270,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); + allocator()->deallocate(std::bit_cast<std::byte*>(m_repr.large.data), m_repr.large.capacity); setSmall(); m_repr.small.length = len & smallStringLengthMask; copyMem(m_repr.small.buffer, temp); @@ -292,16 +283,15 @@ 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()); + + auto* newData = std::bit_cast<utf8*>(allocResult.takeOkay()); fudAssert(newData != nullptr); auto copyResult = copyMem(newData, newCapacity, data(), length()); 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); + allocator()->deallocate(std::bit_cast<std::byte*>(m_repr.large.data), m_repr.large.capacity); } size_t len = length(); @@ -773,7 +763,6 @@ bool String::operator==(const String& rhs) const return diffResult.getOkay() == 0; } - FudStatus String::clear() { if (!valid()) { |