[ox/std] Add move constructor and set null terminator for String
This commit is contained in:
parent
540e67fcd8
commit
19422ced3e
17
deps/ox/src/ox/std/string.cpp
vendored
17
deps/ox/src/ox/std/string.cpp
vendored
@ -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);
|
||||
|
2
deps/ox/src/ox/std/string.hpp
vendored
2
deps/ox/src/ox/std/string.hpp
vendored
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user