Prefer first embedded image that contains the 'front' keyword
This commit is contained in:
@@ -321,6 +321,18 @@ namespace lms::core::stringUtils
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string_view::size_type stringCaseInsensitiveContains(std::string_view str, std::string_view strtoFind)
|
||||
{
|
||||
if (str.empty() && strtoFind.empty())
|
||||
return true; // same as std
|
||||
|
||||
const auto it{ std::search(
|
||||
std::cbegin(str), std::cend(str),
|
||||
std::cbegin(strtoFind), std::cend(strtoFind),
|
||||
[](char chA, char chB) { return std::tolower(chA) == std::tolower(chB); }) };
|
||||
return (it != std::cend(str));
|
||||
}
|
||||
|
||||
void capitalize(std::string& str)
|
||||
{
|
||||
for (auto it{ std::begin(str) }; it != std::end(str); ++it)
|
||||
|
||||
@@ -62,6 +62,7 @@ namespace lms::core::stringUtils
|
||||
[[nodiscard]] std::string bufferToString(std::span<const unsigned char> data);
|
||||
|
||||
[[nodiscard]] bool stringCaseInsensitiveEqual(std::string_view strA, std::string_view strB);
|
||||
[[nodiscard]] std::string_view::size_type stringCaseInsensitiveContains(std::string_view str, std::string_view strtoFind);
|
||||
|
||||
void capitalize(std::string& str);
|
||||
|
||||
|
||||
@@ -322,4 +322,16 @@ namespace lms::core::stringUtils::tests
|
||||
EXPECT_FALSE(stringEndsWith("FooBar", "1FooBar"));
|
||||
EXPECT_FALSE(stringEndsWith("FooBar", "R"));
|
||||
}
|
||||
|
||||
TEST(StringUtils, stringCaseInsensitiveContains)
|
||||
{
|
||||
EXPECT_TRUE(stringCaseInsensitiveContains("FooBar", "Bar"));
|
||||
EXPECT_TRUE(stringCaseInsensitiveContains("FooBar", "bar"));
|
||||
EXPECT_TRUE(stringCaseInsensitiveContains("FooBar", "Foo"));
|
||||
EXPECT_TRUE(stringCaseInsensitiveContains("FooBar", "foo"));
|
||||
EXPECT_FALSE(stringCaseInsensitiveContains("something", "foo"));
|
||||
EXPECT_TRUE(stringCaseInsensitiveContains("FooBar", ""));
|
||||
EXPECT_TRUE(stringCaseInsensitiveContains("", ""));
|
||||
EXPECT_FALSE(stringCaseInsensitiveContains("", "Foo"));
|
||||
}
|
||||
} // namespace lms::core::stringUtils::tests
|
||||
Reference in New Issue
Block a user