diff options
| author | Martin Hořeňovský | 2021-12-26 00:27:11 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2021-12-26 00:35:46 +0100 |
| commit | 187bf6db2bf6724481599526622f8881f4a46cee (patch) | |
| tree | 062a18ad6b63314788a913b6c355c4e5a73b8d1c /src/catch2/internal | |
| parent | cde26de803964197e7d5e988a17a8dad0cd3721e (diff) | |
| download | catch3-187bf6db2bf6724481599526622f8881f4a46cee.tar.gz | |
Split out CaseInsensitiveCmp into its own file
Diffstat (limited to 'src/catch2/internal')
| -rw-r--r-- | src/catch2/internal/catch_case_insensitive_comparisons.cpp | 26 | ||||
| -rw-r--r-- | src/catch2/internal/catch_case_insensitive_comparisons.hpp | 24 |
2 files changed, 50 insertions, 0 deletions
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 <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 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 <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
\ No newline at end of file |