File indexing completed on 2026-08-09 09:04:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_URL_GRAMMAR_CHARSET_HPP
0011 #define BOOST_URL_GRAMMAR_CHARSET_HPP
0012
0013 #include <boost/url/detail/config.hpp>
0014 #include <boost/url/grammar/detail/charset.hpp>
0015 #include <boost/core/detail/static_assert.hpp>
0016 #include <cstdint>
0017 #include <type_traits>
0018 #include <utility>
0019
0020 #ifdef BOOST_URL_HAS_CONCEPTS
0021 #include <concepts>
0022 #endif
0023
0024 namespace boost {
0025 namespace urls {
0026 namespace grammar {
0027
0028 namespace implementation_defined
0029 {
0030 template<class T, class = void>
0031 struct is_charset : std::false_type {};
0032
0033 template<class T>
0034 struct is_charset<T, void_t<
0035 decltype(
0036 std::declval<bool&>() =
0037 std::declval<T const&>().operator()(
0038 std::declval<char>())
0039 ) > > : std::true_type
0040 {
0041 };
0042 }
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 template<class T>
0067 using is_charset = BOOST_URL_SEE_BELOW(implementation_defined::is_charset<T>);
0068
0069 #ifdef BOOST_URL_HAS_CONCEPTS
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 template <class T>
0115 concept CharSet =
0116 requires (T const t, char c)
0117 {
0118 { t(c) } -> std::convertible_to<bool>;
0119 };
0120 #endif
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144 template<BOOST_URL_CONSTRAINT(CharSet) CS>
0145 char const*
0146 find_if(
0147 char const* const first,
0148 char const* const last,
0149 CS const& cs) noexcept
0150 {
0151
0152
0153
0154
0155 static_assert(
0156 is_charset<CS>::value,
0157 "CharSet requirements not met");
0158
0159 return detail::find_if(first, last, cs,
0160 detail::has_find_if<CS>{});
0161 }
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182 template<BOOST_URL_CONSTRAINT(CharSet) CS>
0183 char const*
0184 find_if_not(
0185 char const* const first,
0186 char const* const last,
0187 CS const& cs) noexcept
0188 {
0189
0190
0191
0192
0193 static_assert(
0194 is_charset<CS>::value,
0195 "CharSet requirements not met");
0196
0197 return detail::find_if_not(first, last, cs,
0198 detail::has_find_if_not<CS>{});
0199 }
0200
0201
0202
0203 namespace implementation_defined {
0204 template<class CharSet>
0205 struct charset_ref
0206 {
0207 CharSet const& cs_;
0208
0209 constexpr
0210 bool
0211 operator()(char ch) const noexcept
0212 {
0213 return cs_(ch);
0214 }
0215
0216 char const*
0217 find_if(
0218 char const* first,
0219 char const* last) const noexcept
0220 {
0221 return grammar::find_if(
0222 first, last, cs_);
0223 }
0224
0225 char const*
0226 find_if_not(
0227 char const* first,
0228 char const* last) const noexcept
0229 {
0230 return grammar::find_if_not(
0231 first, last, cs_ );
0232 }
0233 };
0234 }
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255 template<BOOST_URL_CONSTRAINT(CharSet) CS>
0256 constexpr
0257 typename std::enable_if<
0258 is_charset<CS>::value &&
0259 ! std::is_same<CS,
0260 implementation_defined::charset_ref<CS> >::value,
0261 implementation_defined::charset_ref<CS> >::type
0262 ref(CS const& cs) noexcept
0263 {
0264 return implementation_defined::charset_ref<CS>{cs};
0265 }
0266
0267 }
0268 }
0269 }
0270
0271 #endif