mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-19 11:43:56 +00:00
NtOpenSection: Do Case-Insensitive String Comparison
This commit is contained in:
@@ -8,12 +8,15 @@
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
namespace utils::string
|
||||
{
|
||||
#ifdef __clang__
|
||||
__attribute__((__format__(__printf__, 1, 2)))
|
||||
#endif
|
||||
const char* va(const char* format, ...);
|
||||
const char*
|
||||
va(const char* format, ...);
|
||||
|
||||
template <typename T, size_t Size>
|
||||
requires(std::is_trivially_copyable_v<T>)
|
||||
@@ -181,4 +184,54 @@ namespace utils::string
|
||||
{
|
||||
return std::ranges::equal(lhs, rhs, [](const auto c1, const auto c2) { return char_to_lower(c1) == char_to_lower(c2); });
|
||||
}
|
||||
|
||||
template <class Elem, class Traits, class Alloc>
|
||||
bool starts_with_ignore_case(const std::basic_string<Elem, Traits, Alloc>& lhs, const std::basic_string<Elem, Traits, Alloc>& rhs)
|
||||
{
|
||||
if (lhs.length() < rhs.length())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::ranges::equal(lhs.substr(0, rhs.length()), rhs,
|
||||
[](const auto c1, const auto c2) { return char_to_lower(c1) == char_to_lower(c2); });
|
||||
}
|
||||
|
||||
template <class Elem, class Traits>
|
||||
bool starts_with_ignore_case(const std::basic_string_view<Elem, Traits>& lhs, const std::basic_string_view<Elem, Traits>& rhs)
|
||||
{
|
||||
if (lhs.length() < rhs.length())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::ranges::equal(lhs.substr(0, rhs.length()), rhs,
|
||||
[](const auto c1, const auto c2) { return char_to_lower(c1) == char_to_lower(c2); });
|
||||
}
|
||||
|
||||
template <class Elem, class Traits, class Alloc>
|
||||
bool ends_with_ignore_case(const std::basic_string<Elem, Traits, Alloc>& lhs, const std::basic_string<Elem, Traits, Alloc>& rhs)
|
||||
{
|
||||
if (lhs.length() < rhs.length())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto start = lhs.length() - rhs.length();
|
||||
return std::ranges::equal(lhs.substr(start, rhs.length()), rhs,
|
||||
[](const auto c1, const auto c2) { return char_to_lower(c1) == char_to_lower(c2); });
|
||||
}
|
||||
|
||||
template <class Elem, class Traits>
|
||||
bool ends_with_ignore_case(const std::basic_string_view<Elem, Traits>& lhs, const std::basic_string_view<Elem, Traits>& rhs)
|
||||
{
|
||||
if (lhs.length() < rhs.length())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto start = lhs.length() - rhs.length();
|
||||
return std::ranges::equal(lhs.substr(start, rhs.length()), rhs,
|
||||
[](const auto c1, const auto c2) { return char_to_lower(c1) == char_to_lower(c2); });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user