[ox/std] Add move constructor and set null terminator for String

This commit is contained in:
Gary Talent 2020-04-07 22:03:19 -05:00
parent 540e67fcd8
commit 19422ced3e
2 changed files with 17 additions and 2 deletions

View File

@ -12,15 +12,24 @@
namespace ox {
String::String() noexcept {
m_buff.push_back(0);
if (m_buff.size()) {
m_buff[0] = 0;;
} else {
m_buff.push_back(0);
}
}
String::String(std::size_t cap) noexcept {
m_buff.resize(cap + 1);
m_buff[0] = 0;;
}
String::String(const char *str) noexcept {
m_buff.push_back(0);
if (m_buff.size()) {
m_buff[0] = 0;;
} else {
m_buff.push_back(0);
}
*this = str;
}
@ -28,6 +37,10 @@ String::String(String &other) noexcept {
m_buff = other.m_buff;
}
String::String(String &&other) noexcept {
m_buff = ox::move(other.m_buff);
}
const String &String::operator=(const char *str) noexcept {
std::size_t strLen = ox_strlen(str) + 1;
m_buff.resize(strLen + 1);

View File

@ -29,6 +29,8 @@ class String {
String(String&) noexcept;
String(String&&) noexcept;
const String &operator=(const char *str) noexcept;
const String &operator=(char *str) noexcept;