From 55ea405a549ac73c4e56fc1c4cfffd02c2589a59 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 31 Dec 2022 17:14:09 -0600 Subject: [PATCH] [ox/std] Add toStdStringView and endsWith functions --- deps/ox/src/ox/std/stringview.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/deps/ox/src/ox/std/stringview.hpp b/deps/ox/src/ox/std/stringview.hpp index 2c819b50..3a2ed0a0 100644 --- a/deps/ox/src/ox/std/stringview.hpp +++ b/deps/ox/src/ox/std/stringview.hpp @@ -8,6 +8,10 @@ #pragma once +#ifdef OX_USE_STDLIB +#include +#endif + #include "iterator.hpp" #include "strops.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; } +#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") == StringView("Read")); static_assert(StringView("Read") != StringView("Write"));