summaryrefslogtreecommitdiff
path: root/include/fud_string.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/fud_string.hpp')
-rw-r--r--include/fud_string.hpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/include/fud_string.hpp b/include/fud_string.hpp
index a20b067..4b3dbe2 100644
--- a/include/fud_string.hpp
+++ b/include/fud_string.hpp
@@ -31,6 +31,7 @@
#include <climits>
#include <cstddef>
+// NOLINTNEXTLINE(readability-magic-numbers)
static_assert(CHAR_BIT == 8);
/** @file */
@@ -132,6 +133,7 @@ class String {
if constexpr (std::is_same_v<decltype(cStringItem), const char*>) {
cString = cStringItem;
} else if constexpr (std::is_same_v<decltype(cStringItem), const utf8*>) {
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
cString = reinterpret_cast<const char*>(cStringItem);
} else {
static_assert(!std::is_same_v<decltype(cStringItem), const char*>);
@@ -155,6 +157,7 @@ class String {
fudAssert(totalLength < maxStringLength);
String output{};
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
output.m_allocator = reinterpret_cast<uintptr_t>(allocator);
utf8* data{nullptr};
size_t outputCapacity = totalLength + 1;
@@ -208,6 +211,8 @@ class String {
*/
String& operator=(String&& rhs) noexcept;
+ static StringResult withAllocator(Allocator& allocator);
+
/** \brief Create a String by copying from an existing rhs, optionally
* specifying a different allocator. If allocatorOption is NullOpt, the
* allocator from rhs is used.
@@ -269,12 +274,13 @@ class String {
}
/** \brief The underlying data as an explicit c string. */
- [[nodiscard]] inline const char* c_str() const
+ [[nodiscard]] const char* c_str() const
{
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
return reinterpret_cast<const char*>(data());
}
- [[nodiscard]] inline StringView asView() const
+ [[nodiscard]] StringView asView() const
{
return StringView(*this);
}
@@ -336,9 +342,9 @@ class String {
FudStatus clear();
- const utf8* begin() const;
+ [[nodiscard]] const utf8* begin() const;
- const utf8* end() const;
+ [[nodiscard]] const utf8* end() const;
private:
static constexpr size_t maxStringLength = (static_cast<size_t>(1) << 63) - 1;
@@ -349,11 +355,13 @@ class String {
[[nodiscard]] static bool allocatorValid(Allocator* allocator)
{
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
return (reinterpret_cast<uintptr_t>(allocator) & isLargeMask) == 0;
}
- Allocator* allocator() const
+ [[nodiscard]] Allocator* allocator() const
{
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,performance-no-int-to-ptr)
auto* allocPtr = reinterpret_cast<Allocator*>(m_allocator & allocatorMask);
fudAssert(allocPtr != nullptr);
return allocPtr;
@@ -380,6 +388,7 @@ class String {
/** \brief The allocator used to get storage for characters when the string
* is large. */
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
uintptr_t m_allocator{reinterpret_cast<uintptr_t>(&globalFudAllocator)};
using BufType = Array<utf8, SsoBufSize>;