[ox/std] Add caseInsensitiveEquals
This commit is contained in:
+21
@@ -36,6 +36,27 @@ constexpr StringView substr(StringViewCR str, std::size_t const start, std::size
|
|||||||
return {};
|
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]]
|
[[nodiscard]]
|
||||||
constexpr bool beginsWith(StringViewCR base, char const beginning) noexcept {
|
constexpr bool beginsWith(StringViewCR base, char const beginning) noexcept {
|
||||||
return base.size() && base[0] == beginning;
|
return base.size() && base[0] == beginning;
|
||||||
|
|||||||
Reference in New Issue
Block a user