Added startsWithIgnoreCase() and endsWithIgnoreCase() functions.
This commit is contained in:
parent
a64bfde6af
commit
f6776d233d
@ -387,13 +387,36 @@ constexpr bool isHexadecimalChar(TChar chr) noexcept
|
|||||||
|| (chr >= TChar('a') && chr <= TChar('f'));
|
|| (chr >= TChar('a') && chr <= TChar('f'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename TChar>
|
||||||
|
bool compareIgnoreCase(TChar left, TChar right) MIJIN_NOEXCEPT
|
||||||
|
{
|
||||||
|
return std::tolower(left) == std::tolower(right);
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline auto findIgnoreCase(std::string_view haystack, std::string_view needle)
|
inline auto findIgnoreCase(std::string_view haystack, std::string_view needle)
|
||||||
{
|
{
|
||||||
return std::ranges::search(haystack, needle, [](char left, char right)
|
return std::ranges::search(haystack, needle, &compareIgnoreCase<char>);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
inline bool startsWithIgnoreCase(std::string_view string, std::string_view part)
|
||||||
{
|
{
|
||||||
return std::tolower(left) == std::tolower(right);
|
if (part.size() > part.size())
|
||||||
});
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return std::ranges::equal(string.substr(0, part.size()), part, &compareIgnoreCase<char>);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
inline bool endsWithIgnoreCase(std::string_view string, std::string_view part)
|
||||||
|
{
|
||||||
|
if (part.size() > part.size())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return std::ranges::equal(string.substr(string.size() - part.size()), part, &compareIgnoreCase<char>);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace pipe
|
namespace pipe
|
||||||
|
Loading…
x
Reference in New Issue
Block a user