diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-11-02 20:45:02 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-11-02 20:45:02 -0500 |
commit | e8422002f84dc4313894a5b3136c44a9005081fd (patch) | |
tree | b41633d9f759306fe9c7c01e209780222b47f5df /include/fud_string.hpp | |
parent | 6c7fd1db481ff10a16ecab958c6542784fa60b9c (diff) |
Allocator deallocate is void rather than returning FudStatus.
Diffstat (limited to 'include/fud_string.hpp')
-rw-r--r-- | include/fud_string.hpp | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/include/fud_string.hpp b/include/fud_string.hpp index 226bb89..59c434a 100644 --- a/include/fud_string.hpp +++ b/include/fud_string.hpp @@ -60,6 +60,8 @@ class String { * \returns FudStatus::AllocFailure if the allocator fails. */ static StringResult makeFromCString(const char* cString); + + /** @copydoc String::makeFromCString(const char* cString) */ static StringResult makeFromCString(const char8_t* cString); /** \brief Create a string from a C String, specifying the allocator. @@ -74,6 +76,8 @@ class String { * \returns FudStatus::AllocFailure if the allocator fails. */ static StringResult makeFromCString(const char* cString, Allocator* allocator); + + /** @copydoc String::makeFromCString(const char* cString, Allocator* allocator) */ static StringResult makeFromCString(const char8_t* cString, Allocator* allocator); /** \brief Create a string from concatenating multiple C Strings. @@ -187,20 +191,33 @@ class String { * fud allocator. */ String() noexcept = default; + /* The copy constructor is deleted because it is fallible. */ String(const String& rhs) = delete; + /** \brief Infallibly moves the string. */ String(String&& rhs) noexcept; - ~String(); + /* Destructors need no documentation. */ + ~String() noexcept; + /* The copy assignment operator not deleted because it is fallible. */ String& operator=(const String& rhs) = delete; + /** \brief Takes ownership of rhs, destroying the contents of this string in + * the process. The allocator is taken from rhs. + */ String& operator=(String&& rhs) noexcept; - static StringResult from(const String& rhs); + /** \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. + */ + static StringResult from(const String& rhs, Option<Allocator*> allocatorOption = NullOpt); + /** \brief Create a String by copying from a view, with the specified allocator. */ static StringResult from(StringView view, Allocator* allocator = &globalFudAllocator); + /** \brief Copy the contents of rhs, without modifying rhs. */ FudStatus copy(const String& rhs); /** \brief The raw length of the string's data, excluding the null terminator. */ @@ -246,12 +263,19 @@ class String { return reinterpret_cast<const char*>(data()); } + /** \brief Indicates if the contents of the string form a valid sequence of + * UTF8 code points. */ [[nodiscard]] bool utf8Valid() const; + /** \brief Attempts to reserve newCapacity bytes of storage. */ FudStatus reserve(size_t newCapacity); + /** \brief Returns the last character in the sequence if the length is + * greater than zero. */ [[nodiscard]] Option<utf8> back(); + /** \brief Returns the remaining capacity for characters excluding the null + * terminating byte. */ [[nodiscard]] size_t remainingLength() const { if (length() > capacity()) { @@ -312,7 +336,9 @@ class String { Allocator* allocator() const { - return reinterpret_cast<Allocator*>(m_allocator & allocatorMask); + auto* allocPtr = reinterpret_cast<Allocator*>(m_allocator & allocatorMask); + fudAssert(allocPtr != nullptr); + return allocPtr; } [[nodiscard]] bool nullTerminated() const; |