[ox/std] Add String constructor that takes a StringLiteral

This commit is contained in:
Gary Talent 2024-04-21 10:31:26 -05:00
parent dfd27afd67
commit ebf3a6961e

View File

@ -15,6 +15,7 @@
#include "algorithm.hpp"
#include "memops.hpp"
#include "serialize.hpp"
#include "stringliteral.hpp"
#include "stringview.hpp"
#include "strops.hpp"
#include "vector.hpp"
@ -41,6 +42,8 @@ class BasicString {
constexpr BasicString(const char *str, std::size_t size) noexcept;
constexpr explicit BasicString(StringLiteral const&str) noexcept;
constexpr explicit BasicString(CRStringView str) noexcept;
constexpr explicit BasicString(BasicString const&) noexcept;
@ -250,14 +253,6 @@ constexpr BasicString<SmallStringSize_v>::BasicString(std::size_t cap) noexcept:
}
}
template<std::size_t SmallStringSize_v>
template<size_t Sz>
constexpr BasicString<SmallStringSize_v>::BasicString(char const (&str)[Sz]) noexcept {
m_buff.resize(Sz + 1);
ox::listcpy(m_buff.data(), str, Sz);
m_buff[Sz] = 0;
}
template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(const char *str) noexcept {
if (!m_buff.empty()) {
@ -285,6 +280,11 @@ constexpr BasicString<SmallStringSize_v>::BasicString(const char *str, std::size
m_buff[size] = 0;
}
template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(StringLiteral const&str) noexcept:
BasicString(StringView{str.data(), str.bytes()}) {
}
template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(CRStringView str) noexcept {
if (m_buff.empty()) {