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.hpp94
1 files changed, 18 insertions, 76 deletions
diff --git a/include/fud_string.hpp b/include/fud_string.hpp
index cd8e8f1..1a38d43 100644
--- a/include/fud_string.hpp
+++ b/include/fud_string.hpp
@@ -18,6 +18,8 @@
#ifndef FUD_STRING_HPP
#define FUD_STRING_HPP
+#include "fud_status.hpp"
+#include "fud_string_view.hpp"
#include "fud_utf8.hpp"
#include <climits>
@@ -92,7 +94,9 @@ class String {
[[nodiscard]] bool utf8Valid() const;
- [[nodiscard]] FudStatus nullTerminate();
+ FudStatus nullTerminate();
+
+ FudStatus reserve(size_t newCapacity);
[[nodiscard]] std::optional<utf8> back();
@@ -105,15 +109,23 @@ class String {
return m_capacity - 1U - m_length;
}
- [[nodiscard]] FudStatus pushBack(char letter);
+ [[nodiscard]] inline StringView asView() const {
+ return StringView(*this);
+ }
+
+ FudStatus pushBack(char letter);
- [[nodiscard]] FudStatus pushBack(utf8 letter);
+ FudStatus pushBack(utf8 letter);
- [[nodiscard]] FudStatus pushBack(const FudUtf8& letter);
+ FudStatus pushBack(const FudUtf8& letter);
std::optional<utf8> pop();
- [[nodiscard]] FudStatus append(StringView source);
+ FudStatus append(const char* source);
+
+ FudStatus append(const String& source);
+
+ FudStatus append(StringView source);
[[nodiscard]] String catenate(const String& rhs) const;
@@ -127,6 +139,7 @@ class String {
private:
void cleanup();
+ FudStatus resize(size_t newCapacity);
using BufType = Array<utf8, SSO_BUF_SIZE>;
union {
@@ -142,77 +155,6 @@ class String {
}
};
-class StringView {
- public:
- constexpr StringView() noexcept : m_length(0), m_data{nullptr}
- {
- }
-
- constexpr StringView(size_t strLen, const utf8* strData) : m_length(strLen), m_data{strData}
- {
- }
-
- StringView(size_t strLen, const char* strData) :
- m_length(strLen), // line break
- m_data{reinterpret_cast<const utf8*>(strData)} // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
- {
- }
-
- explicit constexpr StringView(const StringView& view) noexcept = default;
-
- explicit constexpr StringView(const String& fudString) noexcept : StringView(fudString.length(), fudString.data())
- {
- }
-
- [[nodiscard]] constexpr size_t length() const
- {
- return m_length;
- }
-
- [[nodiscard]] constexpr const utf8* data() const
- {
- return m_data;
- }
-
- [[nodiscard]] bool nullTerminated() const;
-
- [[nodiscard]] bool utf8Valid() const;
-
- Result<size_t, FudStatus> skipWhitespace();
-
- Result<size_t, FudStatus> trimWhitespace();
-
- FudStatus toUint8(uint8_t& number, uint8_t specifiedRadix, size_t& strLen) const;
-
- FudStatus toUint16(uint16_t& number, uint8_t specifiedRadix, size_t& strLen) const;
-
- FudStatus toUint32(uint32_t& number, uint8_t specifiedRadix, size_t& strLen) const;
-
- FudStatus toUint64(uint64_t& number, uint8_t specifiedRadix, size_t& strLen) const;
-
- FudStatus toInt8(int8_t& number, uint8_t specifiedRadix, size_t& strLen) const;
-
- FudStatus toInt16(int16_t& number, uint8_t specifiedRadix, size_t& strLen) const;
-
- FudStatus toInt32(int32_t& number, uint8_t specifiedRadix, size_t& strLen) const;
-
- FudStatus toInt64(int64_t& number, uint8_t specifiedRadix, size_t& strLen) const;
-
- FudStatus toFloat(float& number, size_t& strLen) const;
-
- FudStatus toDouble(double& number, size_t& strLen) const;
-
- private:
- size_t m_length;
- const utf8* m_data;
-};
-
-FudStatus skipWhitespace(StringView& view, size_t& skipIndex);
-
-ssize_t cStringLength(const char* str);
-
-ssize_t cStringLength(const char* str, size_t maxLength);
-
} // namespace fud
#endif