Split out CaseInsensitiveCmp into its own file

This commit is contained in:
Martin Hořeňovský 2021-12-26 00:27:11 +01:00
parent cde26de803
commit 187bf6db2b
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
6 changed files with 55 additions and 17 deletions

View File

@ -36,6 +36,7 @@ set(INTERNAL_HEADERS
${SOURCES_DIR}/generators/catch_generators_all.hpp ${SOURCES_DIR}/generators/catch_generators_all.hpp
${SOURCES_DIR}/interfaces/catch_interfaces_all.hpp ${SOURCES_DIR}/interfaces/catch_interfaces_all.hpp
${SOURCES_DIR}/matchers/internal/catch_matchers_impl.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_console_width.hpp
${SOURCES_DIR}/internal/catch_container_nonmembers.hpp ${SOURCES_DIR}/internal/catch_container_nonmembers.hpp
${SOURCES_DIR}/internal/catch_noncopyable.hpp ${SOURCES_DIR}/internal/catch_noncopyable.hpp
@ -157,6 +158,7 @@ set(IMPL_SOURCES
${SOURCES_DIR}/internal/catch_commandline.cpp ${SOURCES_DIR}/internal/catch_commandline.cpp
${SOURCES_DIR}/internal/catch_source_line_info.cpp ${SOURCES_DIR}/internal/catch_source_line_info.cpp
${SOURCES_DIR}/catch_config.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_console_colour.cpp
${SOURCES_DIR}/internal/catch_context.cpp ${SOURCES_DIR}/internal/catch_context.cpp
${SOURCES_DIR}/internal/catch_debug_console.cpp ${SOURCES_DIR}/internal/catch_debug_console.cpp

View File

@ -45,6 +45,7 @@
#include <catch2/generators/catch_generators_all.hpp> #include <catch2/generators/catch_generators_all.hpp>
#include <catch2/interfaces/catch_interfaces_all.hpp> #include <catch2/interfaces/catch_interfaces_all.hpp>
#include <catch2/internal/catch_assertion_handler.hpp> #include <catch2/internal/catch_assertion_handler.hpp>
#include <catch2/internal/catch_case_insensitive_comparisons.hpp>
#include <catch2/internal/catch_case_sensitive.hpp> #include <catch2/internal/catch_case_sensitive.hpp>
#include <catch2/internal/catch_clara.hpp> #include <catch2/internal/catch_clara.hpp>
#include <catch2/internal/catch_commandline.hpp> #include <catch2/internal/catch_commandline.hpp>

View File

@ -76,21 +76,9 @@ namespace Catch {
#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp> #include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
#include <catch2/internal/catch_string_manip.hpp>
#include <algorithm>
namespace Catch { namespace Catch {
IReporterRegistry::~IReporterRegistry() = default; 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);
});
}
} }

View File

@ -8,6 +8,7 @@
#ifndef CATCH_INTERFACES_REPORTER_REGISTRY_HPP_INCLUDED #ifndef CATCH_INTERFACES_REPORTER_REGISTRY_HPP_INCLUDED
#define CATCH_INTERFACES_REPORTER_REGISTRY_HPP_INCLUDED #define CATCH_INTERFACES_REPORTER_REGISTRY_HPP_INCLUDED
#include <catch2/internal/catch_case_insensitive_comparisons.hpp>
#include <catch2/internal/catch_unique_ptr.hpp> #include <catch2/internal/catch_unique_ptr.hpp>
#include <string> #include <string>
@ -24,11 +25,7 @@ namespace Catch {
using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>; using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
struct IReporterRegistry { struct IReporterRegistry {
struct CaseInsensitiveCmp { using FactoryMap = std::map<std::string, IReporterFactoryPtr, Detail::CaseInsensitiveLess>;
bool operator()(std::string const& lhs, std::string const& rhs) const;
};
using FactoryMap = std::map<std::string, IReporterFactoryPtr, CaseInsensitiveCmp>;
using Listeners = std::vector<IReporterFactoryPtr>; using Listeners = std::vector<IReporterFactoryPtr>;
virtual ~IReporterRegistry(); // = default virtual ~IReporterRegistry(); // = default

View File

@ -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 <catch2/internal/catch_case_insensitive_comparisons.hpp>
#include <catch2/internal/catch_string_manip.hpp>
#include <algorithm>
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

View File

@ -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 <string>
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