File indexing completed on 2025-07-06 08:32:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_URL_GRAMMAR_LUT_CHARS_HPP
0011 #define BOOST_URL_GRAMMAR_LUT_CHARS_HPP
0012
0013 #include <boost/url/detail/config.hpp>
0014 #include <boost/url/grammar/detail/charset.hpp>
0015 #include <cstdint>
0016 #include <type_traits>
0017
0018
0019
0020
0021 namespace boost {
0022 namespace urls {
0023 namespace grammar {
0024
0025 #ifndef BOOST_URL_DOCS
0026 namespace detail {
0027 template<class T, class = void>
0028 struct is_pred : std::false_type {};
0029
0030 template<class T>
0031 struct is_pred<T, void_t<
0032 decltype(
0033 std::declval<bool&>() =
0034 std::declval<T const&>().operator()(
0035 std::declval<char>())
0036 ) > > : std::true_type
0037 {
0038 };
0039 }
0040 #endif
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 class lut_chars
0065 {
0066 std::uint64_t mask_[4] = {};
0067
0068 constexpr
0069 static
0070 std::uint64_t
0071 lo(char c) noexcept
0072 {
0073 return static_cast<
0074 unsigned char>(c) & 3;
0075 }
0076
0077 constexpr
0078 static
0079 std::uint64_t
0080 hi(char c) noexcept
0081 {
0082 return 1ULL << (static_cast<
0083 unsigned char>(c) >> 2);
0084 }
0085
0086 constexpr
0087 static
0088 lut_chars
0089 construct(
0090 char const* s) noexcept
0091 {
0092 return *s
0093 ? lut_chars(*s) +
0094 construct(s+1)
0095 : lut_chars();
0096 }
0097
0098 constexpr
0099 static
0100 lut_chars
0101 construct(
0102 unsigned char ch,
0103 bool b) noexcept
0104 {
0105 return b
0106 ? lut_chars(ch)
0107 : lut_chars();
0108 }
0109
0110 template<class Pred>
0111 constexpr
0112 static
0113 lut_chars
0114 construct(
0115 Pred pred,
0116 unsigned char ch) noexcept
0117 {
0118 return ch == 255
0119 ? construct(ch, pred(static_cast<char>(ch)))
0120 : construct(ch, pred(static_cast<char>(ch))) +
0121 construct(pred, ch + 1);
0122 }
0123
0124 constexpr
0125 lut_chars() = default;
0126
0127 constexpr
0128 lut_chars(
0129 std::uint64_t m0,
0130 std::uint64_t m1,
0131 std::uint64_t m2,
0132 std::uint64_t m3) noexcept
0133 : mask_{ m0, m1, m2, m3 }
0134 {
0135 }
0136
0137 public:
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157 constexpr
0158 lut_chars(char ch) noexcept
0159 : mask_ {
0160 lo(ch) == 0 ? hi(ch) : 0,
0161 lo(ch) == 1 ? hi(ch) : 0,
0162 lo(ch) == 2 ? hi(ch) : 0,
0163 lo(ch) == 3 ? hi(ch) : 0 }
0164 {
0165 }
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 constexpr
0189 lut_chars(
0190 char const* s) noexcept
0191 : lut_chars(construct(s))
0192 {
0193 }
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227 template<class Pred
0228 #ifndef BOOST_URL_DOCS
0229 ,class = typename std::enable_if<
0230 detail::is_pred<Pred>::value &&
0231 ! std::is_base_of<
0232 lut_chars, Pred>::value>::type
0233 #endif
0234 >
0235 constexpr
0236 lut_chars(Pred const& pred) noexcept
0237 : lut_chars(
0238 construct(pred, 0))
0239 {
0240 }
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256 constexpr
0257 bool
0258 operator()(
0259 unsigned char ch) const noexcept
0260 {
0261 return operator()(static_cast<char>(ch));
0262 }
0263
0264
0265 constexpr
0266 bool
0267 operator()(char ch) const noexcept
0268 {
0269 return mask_[lo(ch)] & hi(ch);
0270 }
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299 friend
0300 constexpr
0301 lut_chars
0302 operator+(
0303 lut_chars const& cs0,
0304 lut_chars const& cs1) noexcept
0305 {
0306 return lut_chars(
0307 cs0.mask_[0] | cs1.mask_[0],
0308 cs0.mask_[1] | cs1.mask_[1],
0309 cs0.mask_[2] | cs1.mask_[2],
0310 cs0.mask_[3] | cs1.mask_[3]);
0311 }
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336 friend
0337 constexpr
0338 lut_chars
0339 operator-(
0340 lut_chars const& cs0,
0341 lut_chars const& cs1) noexcept
0342 {
0343 return lut_chars(
0344 cs0.mask_[0] & ~cs1.mask_[0],
0345 cs0.mask_[1] & ~cs1.mask_[1],
0346 cs0.mask_[2] & ~cs1.mask_[2],
0347 cs0.mask_[3] & ~cs1.mask_[3]);
0348 }
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371 constexpr
0372 lut_chars
0373 operator~() const noexcept
0374 {
0375 return lut_chars(
0376 ~mask_[0],
0377 ~mask_[1],
0378 ~mask_[2],
0379 ~mask_[3]
0380 );
0381 }
0382
0383 #ifndef BOOST_URL_DOCS
0384 #ifdef BOOST_URL_USE_SSE2
0385 char const*
0386 find_if(
0387 char const* first,
0388 char const* last) const noexcept
0389 {
0390 return detail::find_if_pred(
0391 *this, first, last);
0392 }
0393
0394 char const*
0395 find_if_not(
0396 char const* first,
0397 char const* last) const noexcept
0398 {
0399 return detail::find_if_not_pred(
0400 *this, first, last);
0401 }
0402 #endif
0403 #endif
0404 };
0405
0406 }
0407 }
0408 }
0409
0410 #endif