From 5cbf7893748183995e630c4d9586d6a7fedc0001 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 3 Dec 2023 22:14:42 -0600 Subject: [PATCH] [ox/std] Add lastIndexOf(StringView, char) --- deps/ox/src/ox/std/strops.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/deps/ox/src/ox/std/strops.hpp b/deps/ox/src/ox/std/strops.hpp index 68407c76..b1d60319 100644 --- a/deps/ox/src/ox/std/strops.hpp +++ b/deps/ox/src/ox/std/strops.hpp @@ -132,4 +132,15 @@ constexpr ox::Vector split(CRStringView str, CRStringVi return out; } +[[nodiscard]] +constexpr ox::Result lastIndexOf(ox::CRStringView str, int character) noexcept { + ox::Result retval = OxError(1, "Character not found"); + for (auto i = static_cast(str.bytes() - 1); i >= 0; --i) { + if (str[static_cast(i)] == character) { + retval = static_cast(i); + } + } + return retval; +} + }