diff --git a/deps/ox/src/ox/std/string.hpp b/deps/ox/src/ox/std/string.hpp index 8b930920..1c6f7651 100644 --- a/deps/ox/src/ox/std/string.hpp +++ b/deps/ox/src/ox/std/string.hpp @@ -32,6 +32,9 @@ class BasicString { constexpr explicit BasicString(std::size_t cap) noexcept; + template + constexpr BasicString(char const (&str)[Sz]) noexcept; + constexpr explicit BasicString(const char *str) noexcept; constexpr explicit BasicString(const char8_t *str) noexcept; @@ -167,7 +170,7 @@ class BasicString { constexpr Error append(const char *str, std::size_t strLen) noexcept { auto currentLen = len(); m_buff.resize(m_buff.size() + strLen); - ox::memcpy(&m_buff[currentLen], str, strLen); + ox::listcpy(&m_buff[currentLen], str, strLen); // make sure last element is a null terminator m_buff[currentLen + strLen] = 0; // this can't fail, but it returns an Error to match BString::append @@ -247,6 +250,14 @@ constexpr BasicString::BasicString(std::size_t cap) noexcept: } } +template +template +constexpr BasicString::BasicString(char const (&str)[Sz]) noexcept { + m_buff.resize(Sz + 1); + ox::listcpy(m_buff.data(), str, Sz); + m_buff[Sz] = 0; +} + template constexpr BasicString::BasicString(const char *str) noexcept { if (!m_buff.empty()) { @@ -270,7 +281,7 @@ constexpr BasicString::BasicString(const char8_t *str) noexce template constexpr BasicString::BasicString(const char *str, std::size_t size) noexcept { m_buff.resize(size + 1); - memcpy(m_buff.data(), str, size); + ox::listcpy(m_buff.data(), str, size); m_buff[size] = 0; } @@ -394,8 +405,8 @@ constexpr BasicString BasicString::operato const auto currentLen = len(); BasicString cpy(currentLen + strLen); cpy.m_buff.resize(m_buff.size() + strLen); - memcpy(&cpy.m_buff[0], m_buff.data(), currentLen); - memcpy(&cpy.m_buff[currentLen], str, strLen); + ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen); + ox::listcpy(&cpy.m_buff[currentLen], str, strLen); // make sure last element is a null terminator cpy.m_buff[currentLen + strLen] = 0; return cpy; @@ -425,8 +436,8 @@ constexpr BasicString BasicString::operato const auto currentLen = len(); BasicString cpy(currentLen + strLen); cpy.m_buff.resize(m_buff.size() + strLen); - memcpy(&cpy.m_buff[0], m_buff.data(), currentLen); - memcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1); + ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen); + ox::listcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1); return cpy; } @@ -436,8 +447,8 @@ constexpr BasicString BasicString::operato const auto currentLen = len(); BasicString cpy(currentLen + strLen); cpy.m_buff.resize(m_buff.size() + strLen); - memcpy(&cpy.m_buff[0], m_buff.data(), currentLen); - memcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1); + ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen); + ox::listcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1); return cpy; } @@ -509,7 +520,7 @@ constexpr BasicString BasicString::substr( const auto size = end - begin; BasicString out(size); const auto buff = out.data(); - memcpy(buff, src, size); + ox::listcpy(buff, src, size); buff[size] = 0; return out; } @@ -550,7 +561,7 @@ template constexpr void BasicString::set(const char8_t *str) noexcept { std::size_t strBytes = ox::strlen(str) + 1; m_buff.resize(strBytes); - memcpy(m_buff.data(), str, strBytes); + ox::listcpy(m_buff.data(), str, strBytes); *m_buff.back().value = 0; }