RESTinio
string_caseless_compare.hpp
Go to the documentation of this file.
1/*
2 * RESTinio
3 */
4
12#pragma once
13
16
17namespace restinio
18{
19
20namespace impl
21{
22
23namespace string_caseless_compare_details
24{
25
26constexpr auto
27uchar_at( const char * const from, const std::size_t at ) noexcept
28{
29 return static_cast< unsigned char >( from[ at ] );
30}
31
32} /* namespace string_caseless_compare_details */
33
34//
35// is_equal_caseless()
36//
37
39inline bool
41 const char * a,
42 const char * b,
43 std::size_t size ) noexcept
44{
45 using namespace string_caseless_compare_details;
46
47 const unsigned char * const table = to_lower_lut< unsigned char >();
48
49 for( std::size_t i = 0; i < size; ++i )
50 if( table[ uchar_at( a, i ) ] != table[ uchar_at( b, i ) ] )
51 return false;
52
53 return true;
54}
55
56//
57// is_equal_caseless()
58//
59
61inline bool
63 const char * a,
64 std::size_t a_size,
65 const char * b,
66 std::size_t b_size ) noexcept
67{
68 if( a_size == b_size )
69 {
70 return is_equal_caseless( a, b, a_size );
71 }
72
73 return false;
74}
75
76//
77// is_equal_caseless()
78//
79
81inline bool
83{
84 return is_equal_caseless( a.data(), a.size(), b.data(), b.size() );
85}
86
87} /* namespace impl */
88
89} /* namespace restinio */
90
constexpr auto uchar_at(const char *const from, const std::size_t at) noexcept
bool is_equal_caseless(const char *a, const char *b, std::size_t size) noexcept
Comparator for fields names.
nonstd::string_view string_view_t
Definition: string_view.hpp:19