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.hpp32
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;