File indexing completed on 2025-01-30 10:02:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_URL_DECODE_VIEW_HPP
0011 #define BOOST_URL_DECODE_VIEW_HPP
0012
0013 #include <boost/url/detail/config.hpp>
0014 #include <boost/core/detail/string_view.hpp>
0015 #include <boost/url/encoding_opts.hpp>
0016 #include <boost/url/pct_string_view.hpp>
0017 #include <type_traits>
0018 #include <iterator>
0019 #include <iosfwd>
0020
0021 namespace boost {
0022 namespace urls {
0023
0024
0025
0026 #ifndef BOOST_URL_DOCS
0027 class decode_view;
0028
0029 namespace detail {
0030
0031
0032 template<class... Args>
0033 decode_view
0034 make_decode_view(
0035 Args&&... args) noexcept;
0036
0037 }
0038 #endif
0039
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
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 class decode_view
0088 {
0089 char const* p_ = nullptr;
0090 std::size_t n_ = 0;
0091 std::size_t dn_ = 0;
0092 bool space_as_plus_ = true;
0093
0094 #ifndef BOOST_URL_DOCS
0095 template<class... Args>
0096 friend
0097 decode_view
0098 detail::make_decode_view(
0099 Args&&... args) noexcept;
0100 #endif
0101
0102
0103 BOOST_URL_DECL
0104 explicit
0105 decode_view(
0106 core::string_view s,
0107 std::size_t n,
0108 encoding_opts opt) noexcept;
0109
0110 public:
0111
0112
0113 using value_type = char;
0114
0115
0116
0117 using reference = char;
0118
0119
0120 using const_reference = char;
0121
0122
0123
0124 using size_type = std::size_t;
0125
0126
0127
0128 using difference_type = std::ptrdiff_t;
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138 #ifdef BOOST_URL_DOCS
0139 using iterator = __see_below__;
0140 #else
0141 class iterator;
0142 #endif
0143
0144
0145 using const_iterator = iterator;
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174 decode_view() noexcept = default;
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209 explicit
0210 decode_view(
0211 pct_string_view s,
0212 encoding_opts opt = {}) noexcept
0213 : decode_view(
0214 detail::to_sv(s),
0215 s.decoded_size(),
0216 opt)
0217 {
0218 }
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239 bool
0240 empty() const noexcept
0241 {
0242 return n_ == 0;
0243 }
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263 size_type
0264 size() const noexcept
0265 {
0266 return dn_;
0267 }
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282 iterator
0283 begin() const noexcept;
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298 iterator
0299 end() const noexcept;
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319 reference
0320 front() const noexcept;
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340 reference
0341 back() const noexcept;
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356 BOOST_URL_DECL
0357 bool
0358 starts_with( core::string_view s ) const noexcept;
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373 BOOST_URL_DECL
0374 bool
0375 ends_with( core::string_view s ) const noexcept;
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390 BOOST_URL_DECL
0391 bool
0392 starts_with( char ch ) const noexcept;
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407 BOOST_URL_DECL
0408 bool
0409 ends_with( char ch ) const noexcept;
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419 BOOST_URL_DECL
0420 const_iterator
0421 find( char ch ) const noexcept;
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431 BOOST_URL_DECL
0432 const_iterator
0433 rfind( char ch ) const noexcept;
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452 BOOST_URL_DECL
0453 void
0454 remove_prefix( size_type n );
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473 BOOST_URL_DECL
0474 void
0475 remove_suffix( size_type n );
0476
0477
0478
0479 encoding_opts
0480 options() const noexcept
0481 {
0482 encoding_opts opt;
0483 opt.space_as_plus = space_as_plus_;
0484 return opt;
0485 }
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510 BOOST_URL_DECL
0511 int
0512 compare(core::string_view other) const noexcept;
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531 BOOST_URL_DECL
0532 int
0533 compare(decode_view other) const noexcept;
0534
0535
0536
0537
0538 #ifndef BOOST_URL_DOCS
0539 private:
0540 template<class S0, class S1>
0541 using is_match = std::integral_constant<bool,
0542
0543 (
0544 std::is_same<typename std::decay<S0>::type, decode_view>::value ||
0545 std::is_convertible<S0, core::string_view>::value) &&
0546 (
0547 std::is_same<typename std::decay<S1>::type, decode_view>::value ||
0548 std::is_convertible<S1, core::string_view>::value) &&
0549
0550 (
0551 !std::is_convertible<S0, core::string_view>::value ||
0552 !std::is_convertible<S1, core::string_view>::value)>;
0553
0554 static
0555 int
0556 decode_compare(decode_view s0, decode_view s1) noexcept
0557 {
0558 return s0.compare(s1);
0559 }
0560
0561 template <class S>
0562 static
0563 int
0564 decode_compare(decode_view s0, S const& s1) noexcept
0565 {
0566 return s0.compare(s1);
0567 }
0568
0569 template <class S>
0570 static
0571 int
0572 decode_compare(S const& s0, decode_view s1) noexcept
0573 {
0574 return -s1.compare(s0);
0575 }
0576 public:
0577
0578 template<class S0, class S1>
0579 BOOST_CXX14_CONSTEXPR friend auto operator==(
0580 S0 const& s0, S1 const& s1) noexcept ->
0581 typename std::enable_if<
0582 is_match<S0, S1>::value, bool>::type
0583 {
0584 return decode_compare(s0, s1) == 0;
0585 }
0586
0587 template<class S0, class S1>
0588 BOOST_CXX14_CONSTEXPR friend auto operator!=(
0589 S0 const& s0, S1 const& s1) noexcept ->
0590 typename std::enable_if<
0591 is_match<S0, S1>::value, bool>::type
0592 {
0593 return decode_compare(s0, s1) != 0;
0594 }
0595
0596 template<class S0, class S1>
0597 BOOST_CXX14_CONSTEXPR friend auto operator<(
0598 S0 const& s0, S1 const& s1) noexcept ->
0599 typename std::enable_if<
0600 is_match<S0, S1>::value, bool>::type
0601 {
0602 return decode_compare(s0, s1) < 0;
0603 }
0604
0605 template<class S0, class S1>
0606 BOOST_CXX14_CONSTEXPR friend auto operator<=(
0607 S0 const& s0, S1 const& s1) noexcept ->
0608 typename std::enable_if<
0609 is_match<S0, S1>::value, bool>::type
0610 {
0611 return decode_compare(s0, s1) <= 0;
0612 }
0613
0614 template<class S0, class S1>
0615 BOOST_CXX14_CONSTEXPR friend auto operator>(
0616 S0 const& s0, S1 const& s1) noexcept ->
0617 typename std::enable_if<
0618 is_match<S0, S1>::value, bool>::type
0619 {
0620 return decode_compare(s0, s1) > 0;
0621 }
0622
0623 template<class S0, class S1>
0624 BOOST_CXX14_CONSTEXPR friend auto operator>=(
0625 S0 const& s0, S1 const& s1) noexcept ->
0626 typename std::enable_if<
0627 is_match<S0, S1>::value, bool>::type
0628 {
0629 return decode_compare(s0, s1) >= 0;
0630 }
0631 #endif
0632
0633
0634 friend
0635 std::ostream&
0636 operator<<(
0637 std::ostream& os,
0638 decode_view const& s)
0639 {
0640
0641 s.write(os);
0642 return os;
0643 }
0644
0645 private:
0646 BOOST_URL_DECL
0647 void
0648 write(std::ostream& os) const;
0649 };
0650
0651
0652
0653
0654
0655
0656
0657
0658
0659
0660
0661
0662 inline
0663 std::ostream&
0664 operator<<(
0665 std::ostream& os,
0666 decode_view const& s);
0667
0668
0669
0670 inline
0671 decode_view
0672 pct_string_view::operator*() const noexcept
0673 {
0674 return decode_view(*this);
0675 }
0676
0677 #ifndef BOOST_URL_DOCS
0678 namespace detail {
0679 template<class... Args>
0680 decode_view
0681 make_decode_view(
0682 Args&&... args) noexcept
0683 {
0684 return decode_view(
0685 std::forward<Args>(args)...);
0686 }
0687 }
0688 #endif
0689
0690
0691
0692 }
0693 }
0694
0695 #include <boost/url/impl/decode_view.hpp>
0696
0697 #endif