[ox/std] Fix BasicString(const char*) for Linux

This commit is contained in:
Gary Talent 2022-02-20 21:15:30 -06:00
parent 05224e3fb5
commit 5faafad54c

View File

@ -214,6 +214,10 @@ class BasicString {
[[nodiscard]] [[nodiscard]]
std::size_t bytes() const noexcept; std::size_t bytes() const noexcept;
private:
constexpr void set(const char *str) noexcept;
constexpr void set(const char8_t *str) noexcept;
}; };
template<std::size_t SmallStringSize> template<std::size_t SmallStringSize>
@ -240,7 +244,7 @@ constexpr BasicString<SmallStringSize>::BasicString(const char *str) noexcept {
} else { } else {
m_buff.push_back(0); m_buff.push_back(0);
} }
*this = str; set(str);
} }
template<std::size_t SmallStringSize> template<std::size_t SmallStringSize>
@ -250,7 +254,7 @@ constexpr BasicString<SmallStringSize>::BasicString(const char8_t *str) noexcept
} else { } else {
m_buff.push_back(0); m_buff.push_back(0);
} }
this->operator=(str); set(str);
} }
template<std::size_t SmallStringSize> template<std::size_t SmallStringSize>
@ -272,11 +276,7 @@ constexpr BasicString<SmallStringSize>::BasicString(BasicString &&other) noexcep
template<std::size_t SmallStringSize> template<std::size_t SmallStringSize>
BasicString<SmallStringSize> &BasicString<SmallStringSize>::operator=(const char *str) noexcept { BasicString<SmallStringSize> &BasicString<SmallStringSize>::operator=(const char *str) noexcept {
std::size_t strLen = ox_strlen(str) + 1; set(str);
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;
return *this; return *this;
} }
@ -513,6 +513,24 @@ constexpr std::size_t BasicString<SmallStringSize>::len() const noexcept {
return length; return length;
} }
template<std::size_t SmallStringSize>
constexpr void BasicString<SmallStringSize>::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<std::size_t SmallStringSize>
constexpr void BasicString<SmallStringSize>::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>; extern template class BasicString<8>;
using String = BasicString<8>; using String = BasicString<8>;