catch_case_insensitive_comparisons.cpp
1 2 // Copyright Catch2 Authors 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE.txt or copy at 5 // https://www.boost.org/LICENSE_1_0.txt) 6 7 // SPDX-License-Identifier: BSL-1.0 8 9 #include <catch2/internal/catch_case_insensitive_comparisons.hpp> 10 #include <catch2/internal/catch_string_manip.hpp> 11 12 #include <algorithm> 13 14 namespace Catch { 15 namespace Detail { 16 17 bool CaseInsensitiveLess::operator()( StringRef lhs, 18 StringRef rhs ) const { 19 return std::lexicographical_compare( 20 lhs.begin(), lhs.end(), 21 rhs.begin(), rhs.end(), 22 []( char l, char r ) { return toLower( l ) < toLower( r ); } ); 23 } 24 25 bool 26 CaseInsensitiveEqualTo::operator()( StringRef lhs, 27 StringRef rhs ) const { 28 return std::equal( 29 lhs.begin(), lhs.end(), 30 rhs.begin(), rhs.end(), 31 []( char l, char r ) { return toLower( l ) == toLower( r ); } ); 32 } 33 34 } // namespace Detail 35 } // namespace Catch