diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-10-23 13:21:10 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-10-23 13:21:10 -0500 |
commit | 5cc7cbc3704ec255eb5d0ac53b2cc0fcb1221d63 (patch) | |
tree | 169d4d2d8dffe014851712e31a55036deb0c7c0c /include/fud_string_view.hpp | |
parent | b2dbcb55e2832c373fecb4033a3ed77e5dbc77aa (diff) |
String conversion and parsing format spec.
Diffstat (limited to 'include/fud_string_view.hpp')
-rw-r--r-- | include/fud_string_view.hpp | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/include/fud_string_view.hpp b/include/fud_string_view.hpp index 8a47ae5..0852645 100644 --- a/include/fud_string_view.hpp +++ b/include/fud_string_view.hpp @@ -20,6 +20,8 @@ #include "fud_status.hpp" #include "fud_utf8.hpp" +#include "fud_config.hpp" +#include "fud_assert.hpp" #include <string_view> @@ -63,6 +65,25 @@ struct StringView { return m_data; } + constexpr const utf8& operator[](size_t index) const + { + if constexpr (fudBoundsChecking) { + fudAssert(m_data != nullptr); + fudAssert(index < m_length); + } + return m_data[index]; + } + + constexpr const utf8* begin() const noexcept + { + return m_data; + } + + constexpr const utf8* end() const noexcept + { + return m_data + m_length; + } + [[nodiscard]] bool nullTerminated() const; [[nodiscard]] bool utf8Valid() const; @@ -79,26 +100,6 @@ struct StringView { void advanceUnsafe(size_t size); - 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; - size_t m_length{0}; const utf8* m_data{nullptr}; |