// // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // Official repository: https://github.com/boostorg/url // #ifndef BOOST_URL_GRAMMAR_DETAIL_CI_STRING_HPP #define BOOST_URL_GRAMMAR_DETAIL_CI_STRING_HPP #include #include #include #include #include namespace boost { namespace urls { namespace grammar { namespace detail { template struct is_char_iter : std::false_type {}; template struct is_char_iter() = *std::declval()), decltype(std::declval() = ++std::declval()), decltype(std::declval() = std::declval() == std::declval()) > > : std::integral_constant::value> { }; template struct is_char_range : std::false_type {}; template struct is_char_range().begin()), decltype(std::declval().end()) > > : std::integral_constant( ).begin())>::value && is_char_iter( ).end())>::value> { }; template struct type_id_impl { static constexpr char cid = 0; }; template constexpr char type_id_impl::cid; template constexpr std::uintptr_t type_id() noexcept { return std::uintptr_t( &type_id_impl::cid); } //------------------------------------------------ constexpr char to_lower(char c) noexcept { return (c >= 'A' && c <= 'Z') ? c + 'a' - 'A' : c; } constexpr char to_upper(char c) noexcept { return (c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c; } //------------------------------------------------ template auto ci_is_equal( S0 const& s0, S1 const& s1) -> typename std::enable_if< ! std::is_convertible< S0, core::string_view>::value || ! std::is_convertible< S1, core::string_view>::value, bool>::type { /* If you get a compile error here, it means that a range you passed does not meet the requirements stated in the documentation. */ static_assert( is_char_range::value, "Type requirements not met"); static_assert( is_char_range::value, "Type requirements not met"); // Arguments are sorted by type to // reduce the number of function // template instantiations. This // works because: // // ci_is_equal(s0,s1) == ci_is_equal(s1,s0) // BOOST_ASSERT( detail::type_id() <= detail::type_id()); auto it0 = s0.begin(); auto it1 = s1.begin(); auto const end0 = s0.end(); auto const end1 = s1.end(); for(;;) { if(it0 == end0) return it1 == end1; if(it1 == end1) return false; if( to_lower(*it0) != to_lower(*it1)) return false; ++it0; ++it1; } } //------------------------------------------------ BOOST_URL_DECL bool ci_is_equal( core::string_view s0, core::string_view s1) noexcept; BOOST_URL_DECL bool ci_is_less( core::string_view s0, core::string_view s1) noexcept; } // detail } // grammar } // urls } // boost #endif