From 5faafad54c96681d7493df77c522100a3c7b6696 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 20 Feb 2022 21:15:30 -0600 Subject: [PATCH] [ox/std] Fix BasicString(const char*) for Linux --- deps/ox/src/ox/std/string.hpp | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/deps/ox/src/ox/std/string.hpp b/deps/ox/src/ox/std/string.hpp index 9d452c60..f6d4dc13 100644 --- a/deps/ox/src/ox/std/string.hpp +++ b/deps/ox/src/ox/std/string.hpp @@ -214,6 +214,10 @@ class BasicString { [[nodiscard]] std::size_t bytes() const noexcept; + private: + constexpr void set(const char *str) noexcept; + + constexpr void set(const char8_t *str) noexcept; }; template @@ -240,7 +244,7 @@ constexpr BasicString::BasicString(const char *str) noexcept { } else { m_buff.push_back(0); } - *this = str; + set(str); } template @@ -250,7 +254,7 @@ constexpr BasicString::BasicString(const char8_t *str) noexcept } else { m_buff.push_back(0); } - this->operator=(str); + set(str); } template @@ -272,11 +276,7 @@ constexpr BasicString::BasicString(BasicString &&other) noexcep template BasicString &BasicString::operator=(const char *str) noexcept { - std::size_t strLen = ox_strlen(str) + 1; - m_buff.resize(strLen + 1); - memcpy(m_buff.data(), str, strLen); - // make sure last element is a null terminator - m_buff[m_buff.size() - 1] = 0; + set(str); return *this; } @@ -513,6 +513,24 @@ constexpr std::size_t BasicString::len() const noexcept { return length; } +template +constexpr void BasicString::set(const char *str) noexcept { + std::size_t strLen = ox_strlen(str) + 1; + m_buff.resize(strLen + 1); + memcpy(m_buff.data(), str, strLen); + // make sure last element is a null terminator + m_buff[m_buff.size() - 1] = 0; +} + +template +constexpr void BasicString::set(const char8_t *str) noexcept { + std::size_t strLen = ox_strlen(str) + 1; + m_buff.resize(strLen + 1); + memcpy(m_buff.data(), str, strLen); + // make sure last element is a null terminator + m_buff[m_buff.size() - 1] = 0; +} + extern template class BasicString<8>; using String = BasicString<8>;