summaryrefslogtreecommitdiff
path: root/include/fud_string.hpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-11-03 09:28:13 -0600
committerDominick Allen <djallen@librehumanitas.org>2024-11-03 09:28:13 -0600
commitc3fe2de828576900021d27a52114ebdb0a4cb6f0 (patch)
tree34d15165765e15894e2bedbc065081ee1d27ec06 /include/fud_string.hpp
parente8422002f84dc4313894a5b3136c44a9005081fd (diff)
Factor out growth of String and make it scale by 1.5x.
Diffstat (limited to 'include/fud_string.hpp')
-rw-r--r--include/fud_string.hpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/include/fud_string.hpp b/include/fud_string.hpp
index 59c434a..86261c4 100644
--- a/include/fud_string.hpp
+++ b/include/fud_string.hpp
@@ -251,6 +251,17 @@ class String {
return SsoBufSize - 1U;
}
+ /** \brief Returns the remaining capacity for characters excluding the null
+ * terminating byte. */
+ [[nodiscard]] size_t remainingCapacity() const
+ {
+ if (length() > capacity()) {
+ return 0;
+ }
+
+ return capacity() - length();
+ }
+
/** \brief The underlying data, guaranteed to have c string representation. */
[[nodiscard]] const utf8* data() const
{
@@ -263,6 +274,11 @@ class String {
return reinterpret_cast<const char*>(data());
}
+ [[nodiscard]] inline StringView asView() const
+ {
+ return StringView(*this);
+ }
+
/** \brief Indicates if the contents of the string form a valid sequence of
* UTF8 code points. */
[[nodiscard]] bool utf8Valid() const;
@@ -274,22 +290,6 @@ class String {
* 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()) {
- return 0;
- }
-
- return capacity() - length();
- }
-
- [[nodiscard]] inline StringView asView() const
- {
- return StringView(*this);
- }
-
FudStatus pushBack(char letter);
FudStatus pushBack(utf8 letter);
@@ -358,6 +358,8 @@ class String {
FudStatus resize(size_t newCapacity);
+ FudStatus grow();
+
/** \brief The allocator used to get storage for characters when the string
* is large. */
uintptr_t m_allocator{reinterpret_cast<uintptr_t>(&globalFudAllocator)};