From 3cde56717f4074089b627fca4dc944d0d27ee535 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 13 Sep 2026 07:36:43 +0200 Subject: [PATCH] EqualNoCase --- Bigfoot/Libs/Utils/Include/Utils/String.hpp | 24 ++++++++++++++ Bigfoot/Libs/Utils/String.cpp | 35 +++++++++++++++++++++ Bigfoot/Tests/Utils/String.cpp | 32 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 Bigfoot/Libs/Utils/Include/Utils/String.hpp create mode 100644 Bigfoot/Libs/Utils/String.cpp create mode 100644 Bigfoot/Tests/Utils/String.cpp diff --git a/Bigfoot/Libs/Utils/Include/Utils/String.hpp b/Bigfoot/Libs/Utils/Include/Utils/String.hpp new file mode 100644 index 0000000..1f15397 --- /dev/null +++ b/Bigfoot/Libs/Utils/Include/Utils/String.hpp @@ -0,0 +1,24 @@ +/********************************************************************* + * \file String.hpp + * + * \author Romain BOULLARD + * \date September 2026 + *********************************************************************/ +#ifndef BIGFOOT_UTILS_STRING_HPP +#define BIGFOOT_UTILS_STRING_HPP +#include + +namespace Bigfoot +{ +/** + * Check if p_a and p_b are equal, ignoring case + * + * \param p_a The first string + * \param p_b The second string + * \return True if p_a and p_b are equal, false otherwise + */ +[[nodiscard]] +bool EqualNoCase(eastl::string_view p_a, eastl::string_view p_b); +} // namespace Bigfoot + +#endif diff --git a/Bigfoot/Libs/Utils/String.cpp b/Bigfoot/Libs/Utils/String.cpp new file mode 100644 index 0000000..0cce201 --- /dev/null +++ b/Bigfoot/Libs/Utils/String.cpp @@ -0,0 +1,35 @@ +/********************************************************************* + * \file String.cpp + * + * \author Romain BOULLARD + * \date September 2026 + *********************************************************************/ +#include + +#include + +#include + +namespace Bigfoot +{ +bool EqualNoCase(const eastl::string_view p_a, const eastl::string_view p_b) +{ + if (p_a.size() != p_b.size()) + { + return false; + } + + const auto toLower = [](const char p_character) + { + return static_cast(std::tolower(static_cast(p_character))); + }; + + return eastl::equal(p_a.begin(), + p_a.end(), + p_b.begin(), + [&toLower](const char p_x, const char p_y) + { + return toLower(p_x) == toLower(p_y); + }); +} +} // namespace Bigfoot diff --git a/Bigfoot/Tests/Utils/String.cpp b/Bigfoot/Tests/Utils/String.cpp new file mode 100644 index 0000000..55a1659 --- /dev/null +++ b/Bigfoot/Tests/Utils/String.cpp @@ -0,0 +1,32 @@ +/********************************************************************* + * \file String.cpp + * + * \author Romain BOULLARD + * \date September 2026 + *********************************************************************/ +#include + +#include + +namespace Bigfoot +{ +class StringFixture: public ::testing::Test +{ + protected: +}; + +/****************************************************************************************/ + +TEST_F(StringFixture, EqualNoCase_ShouldReturnTrueForTheSameStringWithDifferentCasing) +{ + EXPECT_TRUE(EqualNoCase("NVIDIA GeForce RTX 5080", "nvidia geforce rtx 5080")); + EXPECT_TRUE(EqualNoCase("NVIDIA GeForce RTX 5080", "NVIDIA GeForce RTX 5080")); +} + +/****************************************************************************************/ + +TEST_F(StringFixture, EqualNoCase_ShouldReturnFalseForDifferentStrings) +{ + EXPECT_FALSE(EqualNoCase("NVIDIA GeForce RTX 5080", "AMD Radeon RX 7900")); +} +} // namespace Bigfoot