From 187bf6db2bf6724481599526622f8881f4a46cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sun, 26 Dec 2021 00:27:11 +0100 Subject: [PATCH] Split out CaseInsensitiveCmp into its own file --- src/CMakeLists.txt | 2 ++ src/catch2/catch_all.hpp | 1 + .../catch_interfaces_combined_tu.cpp | 12 --------- .../catch_interfaces_reporter_registry.hpp | 7 ++--- .../catch_case_insensitive_comparisons.cpp | 26 +++++++++++++++++++ .../catch_case_insensitive_comparisons.hpp | 24 +++++++++++++++++ 6 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 src/catch2/internal/catch_case_insensitive_comparisons.cpp create mode 100644 src/catch2/internal/catch_case_insensitive_comparisons.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f57725a9..93da8c26 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,6 +36,7 @@ set(INTERNAL_HEADERS ${SOURCES_DIR}/generators/catch_generators_all.hpp ${SOURCES_DIR}/interfaces/catch_interfaces_all.hpp ${SOURCES_DIR}/matchers/internal/catch_matchers_impl.hpp + ${SOURCES_DIR}/internal/catch_case_insensitive_comparisons.hpp ${SOURCES_DIR}/internal/catch_console_width.hpp ${SOURCES_DIR}/internal/catch_container_nonmembers.hpp ${SOURCES_DIR}/internal/catch_noncopyable.hpp @@ -157,6 +158,7 @@ set(IMPL_SOURCES ${SOURCES_DIR}/internal/catch_commandline.cpp ${SOURCES_DIR}/internal/catch_source_line_info.cpp ${SOURCES_DIR}/catch_config.cpp + ${SOURCES_DIR}/internal/catch_case_insensitive_comparisons.cpp ${SOURCES_DIR}/internal/catch_console_colour.cpp ${SOURCES_DIR}/internal/catch_context.cpp ${SOURCES_DIR}/internal/catch_debug_console.cpp diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp index 85d8e462..92cdc205 100644 --- a/src/catch2/catch_all.hpp +++ b/src/catch2/catch_all.hpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include diff --git a/src/catch2/interfaces/catch_interfaces_combined_tu.cpp b/src/catch2/interfaces/catch_interfaces_combined_tu.cpp index 0f2f406b..b1ce0928 100644 --- a/src/catch2/interfaces/catch_interfaces_combined_tu.cpp +++ b/src/catch2/interfaces/catch_interfaces_combined_tu.cpp @@ -76,21 +76,9 @@ namespace Catch { #include -#include - -#include namespace Catch { - IReporterRegistry::~IReporterRegistry() = default; - bool IReporterRegistry::CaseInsensitiveCmp::operator()(std::string const& lhs, std::string const& rhs) const { - return std::lexicographical_compare(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end(), - [](char l, char r) { - return toLower(l) < toLower(r); - }); - } - } diff --git a/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp b/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp index 0228f9c3..57c652e7 100644 --- a/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp +++ b/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp @@ -8,6 +8,7 @@ #ifndef CATCH_INTERFACES_REPORTER_REGISTRY_HPP_INCLUDED #define CATCH_INTERFACES_REPORTER_REGISTRY_HPP_INCLUDED +#include #include #include @@ -24,11 +25,7 @@ namespace Catch { using IReporterFactoryPtr = Detail::unique_ptr; struct IReporterRegistry { - struct CaseInsensitiveCmp { - bool operator()(std::string const& lhs, std::string const& rhs) const; - }; - - using FactoryMap = std::map; + using FactoryMap = std::map; using Listeners = std::vector; virtual ~IReporterRegistry(); // = default diff --git a/src/catch2/internal/catch_case_insensitive_comparisons.cpp b/src/catch2/internal/catch_case_insensitive_comparisons.cpp new file mode 100644 index 00000000..3081edb3 --- /dev/null +++ b/src/catch2/internal/catch_case_insensitive_comparisons.cpp @@ -0,0 +1,26 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +#include +#include + +#include + +namespace Catch { + namespace Detail { + + bool CaseInsensitiveLess::operator()( std::string const& lhs, + std::string const& rhs ) const { + return std::lexicographical_compare( + lhs.begin(), lhs.end(), + rhs.begin(), rhs.end(), + []( char l, char r ) { return toLower( l ) < toLower( r ); } ); + } + + } // namespace Detail +} // namespace Catch diff --git a/src/catch2/internal/catch_case_insensitive_comparisons.hpp b/src/catch2/internal/catch_case_insensitive_comparisons.hpp new file mode 100644 index 00000000..372809d4 --- /dev/null +++ b/src/catch2/internal/catch_case_insensitive_comparisons.hpp @@ -0,0 +1,24 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 +#ifndef CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED +#define CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED + +#include + +namespace Catch { + namespace Detail { + //! Provides case-insensitive `op<` semantics when called + struct CaseInsensitiveLess { + bool operator()( std::string const& lhs, + std::string const& rhs ) const; + }; + + } // namespace Detail +} // namespace Catch + +#endif // CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED \ No newline at end of file