[ox/std] Add BasicString::beginsWith
This commit is contained in:
parent
ccfc7d5405
commit
9161a1a8ef
18
deps/ox/src/ox/std/string.hpp
vendored
18
deps/ox/src/ox/std/string.hpp
vendored
@ -166,6 +166,12 @@ class BasicString {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr BasicString substr(std::size_t begin, std::size_t end) const noexcept;
|
constexpr BasicString substr(std::size_t begin, std::size_t end) const noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr bool beginsWith(const char *ending) const noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr bool beginsWith(const BasicString &ending) const noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr bool endsWith(const char *ending) const noexcept;
|
constexpr bool endsWith(const char *ending) const noexcept;
|
||||||
|
|
||||||
@ -454,6 +460,18 @@ constexpr BasicString<SmallStringSize> BasicString<SmallStringSize>::substr(std:
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<std::size_t SmallStringSize>
|
||||||
|
constexpr bool BasicString<SmallStringSize>::beginsWith(const char *beginning) const noexcept {
|
||||||
|
const auto beginningLen = ox::min(ox_strlen(beginning), len());
|
||||||
|
return ox_strncmp(data(), beginning, beginningLen) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t SmallStringSize>
|
||||||
|
constexpr bool BasicString<SmallStringSize>::beginsWith(const BasicString &beginning) const noexcept {
|
||||||
|
const auto sz = ox::min(beginning.len(), len());;
|
||||||
|
return ox_strncmp(data(), beginning.c_str(), sz) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
template<std::size_t SmallStringSize>
|
template<std::size_t SmallStringSize>
|
||||||
constexpr bool BasicString<SmallStringSize>::endsWith(const char *ending) const noexcept {
|
constexpr bool BasicString<SmallStringSize>::endsWith(const char *ending) const noexcept {
|
||||||
const auto endingLen = ox_strlen(ending);
|
const auto endingLen = ox_strlen(ending);
|
||||||
|
5
deps/ox/src/ox/std/test/tests.cpp
vendored
5
deps/ox/src/ox/std/test/tests.cpp
vendored
@ -78,6 +78,11 @@ std::map<std::string, std::function<ox::Error()>> tests = {
|
|||||||
s += "aoeu";
|
s += "aoeu";
|
||||||
oxAssert(s == "asdfaoeu", "String append broken");
|
oxAssert(s == "asdfaoeu", "String append broken");
|
||||||
ox::String ending = "asdf";
|
ox::String ending = "asdf";
|
||||||
|
oxAssert(ending.beginsWith("as"), "String::beginsWith is broken");
|
||||||
|
oxAssert(!ending.beginsWith("aa"), "String::beginsWith is broken");
|
||||||
|
oxAssert(!ending.beginsWith("aaaaaaa"), "String::beginsWith is broken");
|
||||||
|
oxAssert(!ending.beginsWith("li"), "String::beginsWith is broken");
|
||||||
|
oxAssert(!ending.beginsWith("afoif"), "String::beginsWith is broken");
|
||||||
oxAssert(ending.endsWith("df"), "String::endsWith is broken");
|
oxAssert(ending.endsWith("df"), "String::endsWith is broken");
|
||||||
oxAssert(!ending.endsWith("awefawe"), "String::endsWith is broken");
|
oxAssert(!ending.endsWith("awefawe"), "String::endsWith is broken");
|
||||||
oxAssert(!ending.endsWith("eu"), "String::endsWith is broken");
|
oxAssert(!ending.endsWith("eu"), "String::endsWith is broken");
|
||||||
|
Loading…
Reference in New Issue
Block a user