From d1e410ac557aed74107a6e96fc2365544a7ddc9f Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 17 May 2026 14:30:43 -0500 Subject: [PATCH] [ox/std] Add caseInsensitiveEquals --- deps/oxlib/src/std/include/ox/std/strops.hpp | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/deps/oxlib/src/std/include/ox/std/strops.hpp b/deps/oxlib/src/std/include/ox/std/strops.hpp index 86251f44..64a8aec0 100644 --- a/deps/oxlib/src/std/include/ox/std/strops.hpp +++ b/deps/oxlib/src/std/include/ox/std/strops.hpp @@ -36,6 +36,27 @@ constexpr StringView substr(StringViewCR str, std::size_t const start, std::size return {}; } +[[nodiscard]] +constexpr char toUpper(char const c) noexcept { + return c & 0b1101'1111; +} + +[[nodiscard]] +constexpr int caseInsensitiveEquals(ox::StringViewCR a, ox::StringViewCR b) noexcept { + auto const sz = ox::min(a.size(), b.size()); + for (size_t i{}; i < sz; ++i) { + auto const ac = toUpper(a[i]); + auto const bc = toUpper(b[i]); + if (ac < bc) { + return -1; + } + if (ac > bc) { + return 1; + } + } + return 0; +} + [[nodiscard]] constexpr bool beginsWith(StringViewCR base, char const beginning) noexcept { return base.size() && base[0] == beginning;