[ox/std] Add BasicString::substr(begin, end)
This commit is contained in:
parent
dce98590fc
commit
3a2acae093
14
deps/ox/src/ox/std/string.hpp
vendored
14
deps/ox/src/ox/std/string.hpp
vendored
@ -103,6 +103,9 @@ class BasicString {
|
||||
[[nodiscard]]
|
||||
BasicString substr(std::size_t pos) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
BasicString substr(std::size_t begin, std::size_t end) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
bool endsWith(const char *ending) const noexcept;
|
||||
|
||||
@ -362,6 +365,17 @@ BasicString<SmallStringSize> BasicString<SmallStringSize>::substr(std::size_t po
|
||||
return m_buff.data() + pos;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize>
|
||||
BasicString<SmallStringSize> BasicString<SmallStringSize>::substr(std::size_t begin, std::size_t end) const noexcept {
|
||||
const auto src = m_buff.data() + begin;
|
||||
const auto size = end - begin;
|
||||
BasicString<SmallStringSize> out(size);
|
||||
const auto buff = out.data();
|
||||
memcpy(buff, src, size);
|
||||
buff[size] = 0;
|
||||
return move(out);
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize>
|
||||
bool BasicString<SmallStringSize>::endsWith(const char *ending) const noexcept {
|
||||
const auto endingLen = ox_strlen(ending);
|
||||
|
Loading…
x
Reference in New Issue
Block a user