From a96d173fdc3d8c007fe70584366715e69f7a13ed Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 12 Feb 2023 22:30:28 -0600 Subject: [PATCH] [ox/std] Fix BString(StringView) constructor --- deps/ox/src/ox/std/bstring.hpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/deps/ox/src/ox/std/bstring.hpp b/deps/ox/src/ox/std/bstring.hpp index c591e852..4d9b8e31 100644 --- a/deps/ox/src/ox/std/bstring.hpp +++ b/deps/ox/src/ox/std/bstring.hpp @@ -28,6 +28,8 @@ class BString { constexpr BString(const char *str) noexcept; + constexpr BString &operator=(CRStringView str) noexcept; + constexpr BString &operator=(const char *str) noexcept; constexpr BString &operator=(char *str) noexcept; @@ -92,12 +94,12 @@ constexpr BString::BString() noexcept: m_buff{{0}} { template constexpr BString::BString(StringView str) noexcept: m_buff{{0}} { - *this = str; + operator=(str); } template constexpr BString::BString(const char *str) noexcept: m_buff{{0}} { - *this = str; + operator=(str); } template @@ -107,6 +109,18 @@ constexpr BString &BString::operator=(Integer_c auto i) noexcept { return this->operator=(str); } +template +constexpr BString &BString::operator=(ox::CRStringView str) noexcept { + std::size_t strLen = str.bytes() + 1; + if (cap() < strLen) { + strLen = cap(); + } + ox_memcpy(m_buff, str.data(), strLen); + // make sure last element is a null terminator + m_buff[strLen] = 0; + return *this; +} + template constexpr BString &BString::operator=(const char *str) noexcept { std::size_t strLen = ox_strlen(str) + 1;