Added equalsIgnoreCase() function.
This commit is contained in:
parent
ea97d3af48
commit
9ef450df33
@ -8,6 +8,8 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "./iterators.hpp"
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
|
||||
@ -28,7 +30,7 @@ namespace mijin
|
||||
//
|
||||
|
||||
template <typename TRange, typename TValue = typename TRange::value_type>
|
||||
std::string join(const TRange& elements, const char* const delimiter)
|
||||
[[nodiscard]] std::string join(const TRange& elements, const char* const delimiter)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
auto first = std::begin(elements);
|
||||
@ -47,6 +49,25 @@ std::string join(const TRange& elements, const char* const delimiter)
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
template<typename TChar, typename TTraitsA, typename TTraitsB>
|
||||
[[nodiscard]] bool equalsIgnoreCase(std::basic_string_view<TChar, TTraitsA> stringA, std::basic_string_view<TChar, TTraitsB> stringB) noexcept
|
||||
{
|
||||
if (stringA.size() != stringB.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto [charA, charB] : zip(stringA, stringB))
|
||||
{
|
||||
if (std::tolower(charA) != std::tolower(charB))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace pipe
|
||||
{
|
||||
struct Join
|
||||
@ -62,7 +83,6 @@ auto operator|(TIterable&& iterable, const Join& joiner)
|
||||
return join(std::forward<TIterable>(iterable), joiner.delimiter);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mijin
|
||||
|
||||
#endif // !defined(MIJIN_UTIL_STRING_HPP_INCLUDED)
|
||||
|
Loading…
x
Reference in New Issue
Block a user