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;