string_caseless_compare.hpp
Go to the documentation of this file.
/*
* RESTinio
*/
#pragma once
#include <restinio/impl/to_lower_lut.hpp>
#include <restinio/string_view.hpp>
namespace restinio
{
namespace impl
{
namespace string_caseless_compare_details
{
constexpr auto
uchar_at( const char * const from, const std::size_t at ) noexcept
{
return static_cast< unsigned char >( from[ at ] );
}
} /* namespace string_caseless_compare_details */
//
// is_equal_caseless()
//
inline bool
is_equal_caseless(
const char * a,
const char * b,
std::size_t size ) noexcept
{
using namespace string_caseless_compare_details;
const unsigned char * const table = to_lower_lut< unsigned char >();
for( std::size_t i = 0; i < size; ++i )
if( table[ uchar_at( a, i ) ] != table[ uchar_at( b, i ) ] )
return false;
return true;
}
//
// is_equal_caseless()
//
inline bool
is_equal_caseless(
const char * a,
std::size_t a_size,
const char * b,
std::size_t b_size ) noexcept
{
if( a_size == b_size )
{
return is_equal_caseless( a, b, a_size );
}
return false;
}
//
// is_equal_caseless()
//
inline bool
is_equal_caseless( string_view_t a, string_view_t b ) noexcept
{
return is_equal_caseless( a.data(), a.size(), b.data(), b.size() );
}
} /* namespace impl */
} /* namespace restinio */
restinio::impl::string_caseless_compare_details::uchar_at
constexpr auto uchar_at(const char *const from, const std::size_t at) noexcept
Definition: string_caseless_compare.hpp:27
restinio::impl::is_equal_caseless
bool is_equal_caseless(const char *a, const char *b, std::size_t size) noexcept
Comparator for fields names.
Definition: string_caseless_compare.hpp:40
restinio
Definition: asio_include.hpp:21
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
string_view.hpp
to_lower_lut.hpp