File indexing completed on 2025-09-15 08:53:57
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
0257 constexpr
0258 bool
0259 operator()(
0260 unsigned char ch) const noexcept
0261 {
0262 return operator()(static_cast<char>(ch));
0263 }
0264
0265
0266 constexpr
0267 bool
0268 operator()(char ch) const noexcept
0269 {
0270 return mask_[lo(ch)] & hi(ch);
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
0300 friend
0301 constexpr
0302 lut_chars
0303 operator+(
0304 lut_chars const& cs0,
0305 lut_chars const& cs1) noexcept
0306 {
0307 return lut_chars(
0308 cs0.mask_[0] | cs1.mask_[0],
0309 cs0.mask_[1] | cs1.mask_[1],
0310 cs0.mask_[2] | cs1.mask_[2],
0311 cs0.mask_[3] | cs1.mask_[3]);
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
0337 friend
0338 constexpr
0339 lut_chars
0340 operator-(
0341 lut_chars const& cs0,
0342 lut_chars const& cs1) noexcept
0343 {
0344 return lut_chars(
0345 cs0.mask_[0] & ~cs1.mask_[0],
0346 cs0.mask_[1] & ~cs1.mask_[1],
0347 cs0.mask_[2] & ~cs1.mask_[2],
0348 cs0.mask_[3] & ~cs1.mask_[3]);
0349 }
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372 constexpr
0373 lut_chars
0374 operator~() const noexcept
0375 {
0376 return lut_chars(
0377 ~mask_[0],
0378 ~mask_[1],
0379 ~mask_[2],
0380 ~mask_[3]
0381 );
0382 }
0383
0384 #ifndef BOOST_URL_DOCS
0385 #ifdef BOOST_URL_USE_SSE2
0386 char const*
0387 find_if(
0388 char const* first,
0389 char const* last) const noexcept
0390 {
0391 return detail::find_if_pred(
0392 *this, first, last);
0393 }
0394
0395 char const*
0396 find_if_not(
0397 char const* first,
0398 char const* last) const noexcept
0399 {
0400 return detail::find_if_not_pred(
0401 *this, first, last);
0402 }
0403 #endif
0404 #endif
0405 };
0406
0407 }
0408 }
0409 }
0410
0411 #endif