[ox/std] Add lastIndexOf(StringView, char)

This commit is contained in:
Gary Talent 2023-12-03 22:14:42 -06:00
parent 3f83a254d2
commit 5cbf789374

View File

@ -132,4 +132,15 @@ constexpr ox::Vector<ox::StringView, smallSz> split(CRStringView str, CRStringVi
return out; return out;
} }
[[nodiscard]]
constexpr ox::Result<std::size_t> lastIndexOf(ox::CRStringView str, int character) noexcept {
ox::Result<std::size_t> retval = OxError(1, "Character not found");
for (auto i = static_cast<int>(str.bytes() - 1); i >= 0; --i) {
if (str[static_cast<std::size_t>(i)] == character) {
retval = static_cast<std::size_t>(i);
}
}
return retval;
}
} }