[ox/std] Add toStdStringView and endsWith functions

This commit is contained in:
Gary Talent 2022-12-31 17:14:09 -06:00
parent 6cfa8dd40d
commit 55ea405a54

View File

@ -8,6 +8,10 @@
#pragma once #pragma once
#ifdef OX_USE_STDLIB
#include <string_view>
#endif
#include "iterator.hpp" #include "iterator.hpp"
#include "strops.hpp" #include "strops.hpp"
#include "types.hpp" #include "types.hpp"
@ -264,6 +268,12 @@ constexpr bool endsWith(CRStringView base, CRStringView ending) noexcept {
return base.len() >= endingLen && ox_strcmp(base.data() + (base.len() - endingLen), ending) == 0; return base.len() >= endingLen && ox_strcmp(base.data() + (base.len() - endingLen), ending) == 0;
} }
#ifdef OX_USE_STDLIB
constexpr auto toStdStringView(CRStringView sv) noexcept {
return std::string_view(sv.data(), sv.bytes());
}
#endif
static_assert(StringView("Read").bytes() == 4); static_assert(StringView("Read").bytes() == 4);
static_assert(StringView("Read") == StringView("Read")); static_assert(StringView("Read") == StringView("Read"));
static_assert(StringView("Read") != StringView("Write")); static_assert(StringView("Read") != StringView("Write"));