[ox/std] Fix BString(StringView) constructor
This commit is contained in:
parent
5e43eff631
commit
a96d173fdc
18
deps/ox/src/ox/std/bstring.hpp
vendored
18
deps/ox/src/ox/std/bstring.hpp
vendored
@ -28,6 +28,8 @@ class BString {
|
|||||||
|
|
||||||
constexpr BString(const char *str) noexcept;
|
constexpr BString(const char *str) noexcept;
|
||||||
|
|
||||||
|
constexpr BString &operator=(CRStringView str) noexcept;
|
||||||
|
|
||||||
constexpr BString &operator=(const char *str) noexcept;
|
constexpr BString &operator=(const char *str) noexcept;
|
||||||
|
|
||||||
constexpr BString &operator=(char *str) noexcept;
|
constexpr BString &operator=(char *str) noexcept;
|
||||||
@ -92,12 +94,12 @@ constexpr BString<size>::BString() noexcept: m_buff{{0}} {
|
|||||||
|
|
||||||
template<std::size_t size>
|
template<std::size_t size>
|
||||||
constexpr BString<size>::BString(StringView str) noexcept: m_buff{{0}} {
|
constexpr BString<size>::BString(StringView str) noexcept: m_buff{{0}} {
|
||||||
*this = str;
|
operator=(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t size>
|
template<std::size_t size>
|
||||||
constexpr BString<size>::BString(const char *str) noexcept: m_buff{{0}} {
|
constexpr BString<size>::BString(const char *str) noexcept: m_buff{{0}} {
|
||||||
*this = str;
|
operator=(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t size>
|
template<std::size_t size>
|
||||||
@ -107,6 +109,18 @@ constexpr BString<size> &BString<size>::operator=(Integer_c auto i) noexcept {
|
|||||||
return this->operator=(str);
|
return this->operator=(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<std::size_t size>
|
||||||
|
constexpr BString<size> &BString<size>::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<std::size_t size>
|
template<std::size_t size>
|
||||||
constexpr BString<size> &BString<size>::operator=(const char *str) noexcept {
|
constexpr BString<size> &BString<size>::operator=(const char *str) noexcept {
|
||||||
std::size_t strLen = ox_strlen(str) + 1;
|
std::size_t strLen = ox_strlen(str) + 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user