File indexing completed on 2025-09-18 09:07:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_URL_GRAMMAR_STRING_VIEW_BASE_HPP
0011 #define BOOST_URL_GRAMMAR_STRING_VIEW_BASE_HPP
0012
0013 #include <boost/url/detail/config.hpp>
0014 #include <boost/url/detail/string_view.hpp>
0015 #include <boost/core/detail/string_view.hpp>
0016 #include <cstddef>
0017 #include <iterator>
0018 #include <string>
0019 #include <type_traits>
0020 #include <utility>
0021
0022 namespace boost {
0023 namespace urls {
0024 namespace grammar {
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 class string_view_base
0037 {
0038 protected:
0039
0040
0041 core::string_view s_;
0042
0043
0044
0045
0046
0047 constexpr
0048 string_view_base(
0049 core::string_view s) noexcept
0050 : s_(s)
0051 {
0052 }
0053
0054
0055
0056
0057
0058
0059 constexpr
0060 string_view_base(
0061 char const* data,
0062 std::size_t size) noexcept
0063 : s_(data, size)
0064 {
0065 }
0066
0067
0068
0069
0070
0071
0072
0073 void
0074 swap(
0075 string_view_base& s ) noexcept
0076 {
0077 std::swap(s_, s.s_);
0078 }
0079
0080
0081
0082 string_view_base() = default;
0083
0084
0085
0086 string_view_base(
0087 string_view_base const&) = default;
0088
0089
0090
0091
0092
0093
0094 string_view_base& operator=(
0095 string_view_base const& other) = default;
0096
0097 public:
0098
0099 typedef std::char_traits<char> traits_type;
0100
0101 typedef char value_type;
0102
0103 typedef char* pointer;
0104
0105 typedef char const* const_pointer;
0106
0107 typedef char& reference;
0108
0109 typedef char const& const_reference;
0110
0111 typedef char const* const_iterator;
0112
0113 typedef const_iterator iterator;
0114
0115 typedef std::reverse_iterator<
0116 const_iterator> const_reverse_iterator;
0117
0118 typedef const_reverse_iterator reverse_iterator;
0119
0120 typedef std::size_t size_type;
0121
0122 typedef std::ptrdiff_t difference_type;
0123
0124
0125 static constexpr std::size_t npos = core::string_view::npos;
0126
0127
0128
0129
0130
0131
0132
0133 operator
0134 core::string_view() const noexcept
0135 {
0136 return s_;
0137 }
0138
0139
0140
0141
0142
0143 #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
0144 operator
0145 std::string_view() const noexcept
0146 {
0147 return std::string_view(s_);
0148 }
0149 #endif
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160 explicit
0161 operator
0162 std::string() const noexcept
0163 {
0164 return std::string(s_);
0165 }
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177 BOOST_CONSTEXPR const_iterator begin() const noexcept
0178 {
0179 return s_.begin();
0180 }
0181
0182
0183
0184
0185
0186
0187
0188 BOOST_CONSTEXPR const_iterator end() const noexcept
0189 {
0190 return s_.end();
0191 }
0192
0193
0194
0195
0196
0197
0198
0199 BOOST_CONSTEXPR const_iterator cbegin() const noexcept
0200 {
0201 return s_.cbegin();
0202 }
0203
0204
0205
0206
0207
0208
0209
0210 BOOST_CONSTEXPR const_iterator cend() const noexcept
0211 {
0212 return s_.cend();
0213 }
0214
0215
0216
0217
0218
0219
0220
0221 BOOST_URL_LIB_ARRAY_CONSTEXPR
0222 const_reverse_iterator rbegin() const noexcept
0223 {
0224 return s_.rbegin();
0225 }
0226
0227
0228
0229
0230
0231
0232
0233 BOOST_URL_LIB_ARRAY_CONSTEXPR
0234 const_reverse_iterator rend() const noexcept
0235 {
0236 return s_.rend();
0237 }
0238
0239
0240
0241
0242
0243
0244
0245 BOOST_URL_LIB_ARRAY_CONSTEXPR
0246 const_reverse_iterator crbegin() const noexcept
0247 {
0248 return s_.crbegin();
0249 }
0250
0251
0252
0253
0254
0255
0256
0257 BOOST_URL_LIB_ARRAY_CONSTEXPR
0258 const_reverse_iterator crend() const noexcept
0259 {
0260 return s_.crend();
0261 }
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271 BOOST_CONSTEXPR size_type size() const noexcept
0272 {
0273 return s_.size();
0274 }
0275
0276
0277
0278
0279
0280
0281
0282 BOOST_CONSTEXPR size_type length() const noexcept
0283 {
0284 return s_.length();
0285 }
0286
0287
0288
0289
0290
0291
0292
0293 BOOST_CONSTEXPR size_type max_size() const noexcept
0294 {
0295 return s_.max_size();
0296 }
0297
0298
0299
0300
0301
0302
0303
0304 BOOST_CONSTEXPR bool empty() const noexcept
0305 {
0306 return s_.empty();
0307 }
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318 BOOST_CXX14_CONSTEXPR const_reference
0319 operator[]( size_type pos ) const noexcept
0320 {
0321 return s_[pos];
0322 }
0323
0324
0325
0326
0327
0328
0329
0330
0331 BOOST_CXX14_CONSTEXPR const_reference
0332 at( size_type pos ) const
0333 {
0334 return s_.at(pos);
0335 }
0336
0337
0338
0339
0340
0341
0342
0343 BOOST_CXX14_CONSTEXPR const_reference
0344 front() const noexcept
0345 {
0346 return s_.front();
0347 }
0348
0349
0350
0351
0352
0353
0354
0355 BOOST_CXX14_CONSTEXPR const_reference
0356 back() const noexcept
0357 {
0358 return s_.back();
0359 }
0360
0361
0362
0363
0364
0365
0366
0367 BOOST_CONSTEXPR const_pointer
0368 data() const noexcept
0369 {
0370 return s_.data();
0371 }
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384 BOOST_CXX14_CONSTEXPR size_type copy(
0385 char* s, size_type n, size_type pos = 0 ) const
0386 {
0387 return s_.copy(s, n, pos);
0388 }
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398 BOOST_CXX14_CONSTEXPR core::string_view substr(
0399 size_type pos = 0, size_type n = core::string_view::npos ) const
0400 {
0401 return s_.substr(pos, n);
0402 }
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413 BOOST_CXX14_CONSTEXPR int
0414 compare( core::string_view str ) const noexcept
0415 {
0416 return s_.compare(str);
0417 }
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428 BOOST_CONSTEXPR int compare(
0429 size_type pos1, size_type n1, core::string_view str ) const
0430 {
0431 return s_.compare(pos1, n1, str);
0432 }
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445 BOOST_CONSTEXPR int compare(
0446 size_type pos1, size_type n1, core::string_view str,
0447 size_type pos2, size_type n2 ) const
0448 {
0449 return s_.compare(pos1, n1, str, pos2, n2);
0450 }
0451
0452
0453
0454
0455
0456
0457
0458
0459 BOOST_CONSTEXPR int compare(
0460 char const* s ) const noexcept
0461 {
0462 return s_.compare(s);
0463 }
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474 BOOST_CONSTEXPR int compare(
0475 size_type pos1, size_type n1, char const* s ) const
0476 {
0477 return s_.compare(pos1, n1, s);
0478 }
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490 BOOST_CONSTEXPR int compare(
0491 size_type pos1, size_type n1,
0492 char const* s, size_type n2 ) const
0493 {
0494 return s_.compare(pos1, n1, s, n2);
0495 }
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506 BOOST_CONSTEXPR bool starts_with(
0507 core::string_view x ) const noexcept
0508 {
0509 return s_.starts_with(x);
0510 }
0511
0512
0513
0514
0515
0516
0517
0518
0519 BOOST_CONSTEXPR bool starts_with(
0520 char x ) const noexcept
0521 {
0522 return s_.starts_with(x);
0523 }
0524
0525
0526
0527
0528
0529
0530
0531
0532 BOOST_CONSTEXPR bool starts_with(
0533 char const* x ) const noexcept
0534 {
0535 return s_.starts_with(x);
0536 }
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546
0547 BOOST_CONSTEXPR bool ends_with(
0548 core::string_view x ) const noexcept
0549 {
0550 return s_.ends_with(x);
0551 }
0552
0553
0554
0555
0556
0557
0558
0559
0560 BOOST_CONSTEXPR bool ends_with(
0561 char x ) const noexcept
0562 {
0563 return s_.ends_with(x);
0564 }
0565
0566
0567
0568
0569
0570
0571
0572
0573 BOOST_CONSTEXPR bool ends_with(
0574 char const* x ) const noexcept
0575 {
0576 return s_.ends_with(x);
0577 }
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589 BOOST_CONSTEXPR size_type find(
0590 core::string_view str, size_type pos = 0 ) const noexcept
0591 {
0592 return s_.find(str, pos);
0593 }
0594
0595
0596
0597
0598
0599
0600
0601
0602
0603 BOOST_CXX14_CONSTEXPR size_type find(
0604 char c, size_type pos = 0 ) const noexcept
0605 {
0606 return s_.find(c, pos);
0607 }
0608
0609
0610
0611
0612
0613
0614
0615
0616
0617
0618 BOOST_CXX14_CONSTEXPR size_type find(
0619 char const* s, size_type pos, size_type n ) const noexcept
0620 {
0621 return s_.find(s, pos, n);
0622 }
0623
0624
0625
0626
0627
0628
0629
0630
0631
0632 BOOST_CONSTEXPR size_type find(
0633 char const* s, size_type pos = 0 ) const noexcept
0634 {
0635 return s_.find(s, pos);
0636 }
0637
0638
0639
0640
0641
0642
0643
0644
0645
0646
0647
0648 BOOST_CONSTEXPR size_type rfind(
0649 core::string_view str, size_type pos = core::string_view::npos ) const noexcept
0650 {
0651 return s_.rfind(str, pos);
0652 }
0653
0654
0655
0656
0657
0658
0659
0660
0661
0662 BOOST_CXX14_CONSTEXPR size_type rfind(
0663 char c, size_type pos = core::string_view::npos ) const noexcept
0664 {
0665 return s_.rfind(c, pos);
0666 }
0667
0668
0669
0670
0671
0672
0673
0674
0675
0676
0677 BOOST_CXX14_CONSTEXPR size_type rfind(
0678 char const* s, size_type pos, size_type n ) const noexcept
0679 {
0680 return s_.rfind(s, pos, n);
0681 }
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691 BOOST_CONSTEXPR size_type rfind(
0692 char const* s, size_type pos = core::string_view::npos ) const noexcept
0693 {
0694 return s_.rfind(s, pos);
0695 }
0696
0697
0698
0699
0700
0701
0702
0703
0704
0705
0706
0707 BOOST_CXX14_CONSTEXPR size_type find_first_of(
0708 core::string_view str, size_type pos = 0 ) const noexcept
0709 {
0710 return s_.find_first_of(str, pos);
0711 }
0712
0713
0714
0715
0716
0717
0718
0719
0720
0721 BOOST_CONSTEXPR size_type find_first_of(
0722 char c, size_type pos = 0 ) const noexcept
0723 {
0724 return s_.find_first_of(c, pos);
0725 }
0726
0727
0728
0729
0730
0731
0732
0733
0734
0735
0736 BOOST_CXX14_CONSTEXPR size_type find_first_of(
0737 char const* s, size_type pos, size_type n ) const noexcept
0738 {
0739 return s_.find_first_of(s, pos, n);
0740 }
0741
0742
0743
0744
0745
0746
0747
0748
0749
0750 BOOST_CXX14_CONSTEXPR size_type find_first_of(
0751 char const* s, size_type pos = 0 ) const noexcept
0752 {
0753 return s_.find_first_of(s, pos);
0754 }
0755
0756
0757
0758
0759
0760
0761
0762
0763
0764
0765
0766 BOOST_CXX14_CONSTEXPR size_type find_last_of(
0767 core::string_view str, size_type pos = core::string_view::npos ) const noexcept
0768 {
0769 return s_.find_last_of(str, pos);
0770 }
0771
0772
0773
0774
0775
0776
0777
0778
0779
0780 BOOST_CONSTEXPR size_type find_last_of(
0781 char c, size_type pos = core::string_view::npos ) const noexcept
0782 {
0783 return s_.find_last_of(c, pos);
0784 }
0785
0786
0787
0788
0789
0790
0791
0792
0793
0794
0795 BOOST_CXX14_CONSTEXPR size_type find_last_of(
0796 char const* s, size_type pos, size_type n ) const noexcept
0797 {
0798 return s_.find_last_of(s, pos, n);
0799 }
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809 BOOST_CXX14_CONSTEXPR size_type find_last_of(
0810 char const* s, size_type pos = core::string_view::npos ) const noexcept
0811 {
0812 return s_.find_last_of(s, pos);
0813 }
0814
0815
0816
0817
0818
0819
0820
0821
0822
0823
0824
0825 BOOST_CXX14_CONSTEXPR size_type find_first_not_of(
0826 core::string_view str, size_type pos = 0 ) const noexcept
0827 {
0828 return s_.find_first_not_of(str, pos);
0829 }
0830
0831
0832
0833
0834
0835
0836
0837
0838
0839 BOOST_CXX14_CONSTEXPR size_type find_first_not_of(
0840 char c, size_type pos = 0 ) const noexcept
0841 {
0842 return s_.find_first_not_of(c, pos);
0843 }
0844
0845
0846
0847
0848
0849
0850
0851
0852
0853
0854 BOOST_CXX14_CONSTEXPR size_type find_first_not_of(
0855 char const* s, size_type pos, size_type n ) const noexcept
0856 {
0857 return s_.find_first_not_of(s, pos, n);
0858 }
0859
0860
0861
0862
0863
0864
0865
0866
0867
0868 BOOST_CXX14_CONSTEXPR size_type find_first_not_of(
0869 char const* s, size_type pos = 0 ) const noexcept
0870 {
0871 return s_.find_first_not_of(s, pos);
0872 }
0873
0874
0875
0876
0877
0878
0879
0880
0881
0882
0883
0884 BOOST_CXX14_CONSTEXPR size_type find_last_not_of(
0885 core::string_view str, size_type pos = core::string_view::npos ) const noexcept
0886 {
0887 return s_.find_last_not_of(str, pos);
0888 }
0889
0890
0891
0892
0893
0894
0895
0896
0897
0898 BOOST_CXX14_CONSTEXPR size_type find_last_not_of(
0899 char c, size_type pos = core::string_view::npos ) const noexcept
0900 {
0901 return s_.find_last_not_of(c, pos);
0902 }
0903
0904
0905
0906
0907
0908
0909
0910
0911
0912
0913 BOOST_CXX14_CONSTEXPR size_type find_last_not_of(
0914 char const* s, size_type pos, size_type n ) const noexcept
0915 {
0916 return s_.find_last_not_of(s, pos, n);
0917 }
0918
0919
0920
0921
0922
0923
0924
0925
0926
0927 BOOST_CXX14_CONSTEXPR size_type find_last_not_of(
0928 char const* s, size_type pos = core::string_view::npos ) const noexcept
0929 {
0930 return s_.find_last_not_of(s, pos);
0931 }
0932
0933
0934
0935
0936
0937
0938
0939
0940
0941
0942 BOOST_CONSTEXPR bool contains( core::string_view sv ) const noexcept
0943 {
0944 return s_.contains(sv);
0945 }
0946
0947
0948
0949
0950
0951
0952
0953
0954 BOOST_CXX14_CONSTEXPR bool contains( char c ) const noexcept
0955 {
0956 return s_.contains(c);
0957 }
0958
0959
0960
0961
0962
0963
0964
0965
0966 BOOST_CONSTEXPR bool contains( char const* s ) const noexcept
0967 {
0968 return s_.contains(s);
0969 }
0970
0971
0972 #ifndef BOOST_URL_DOCS
0973 private:
0974 template<class S0, class S1>
0975 using is_match = std::integral_constant<bool,
0976 std::is_convertible<S0, core::string_view>::value &&
0977 std::is_convertible<S1, core::string_view>::value && (
0978 (std::is_base_of<string_view_base,
0979 typename std::decay<S0>::type>::value &&
0980 std::is_convertible<S0 const volatile*,
0981 string_view_base const volatile*>::value) ||
0982 (std::is_base_of<string_view_base,
0983 typename std::decay<S1>::type>::value &&
0984 std::is_convertible<S1 const volatile*,
0985 string_view_base const volatile*>::value))>;
0986 public:
0987
0988
0989
0990
0991
0992
0993
0994
0995
0996
0997
0998 template<class S0, class S1>
0999 BOOST_CXX14_CONSTEXPR friend auto operator==(
1000 S0 const& s0, S1 const& s1) noexcept ->
1001 typename std::enable_if<
1002 is_match<S0, S1>::value, bool>::type
1003 {
1004 return urls::detail::to_sv(s0) == urls::detail::to_sv(s1);
1005 }
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017 template<class S0, class S1>
1018 BOOST_CXX14_CONSTEXPR friend auto operator!=(
1019 S0 const& s0, S1 const& s1) noexcept ->
1020 typename std::enable_if<
1021 is_match<S0, S1>::value, bool>::type
1022 {
1023 return urls::detail::to_sv(s0) != urls::detail::to_sv(s1);
1024 }
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036 template<class S0, class S1>
1037 BOOST_CXX14_CONSTEXPR friend auto operator<(
1038 S0 const& s0, S1 const& s1) noexcept ->
1039 typename std::enable_if<
1040 is_match<S0, S1>::value, bool>::type
1041 {
1042 return urls::detail::to_sv(s0) < urls::detail::to_sv(s1);
1043 }
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055 template<class S0, class S1>
1056 BOOST_CXX14_CONSTEXPR friend auto operator<=(
1057 S0 const& s0, S1 const& s1) noexcept ->
1058 typename std::enable_if<
1059 is_match<S0, S1>::value, bool>::type
1060 {
1061 return urls::detail::to_sv(s0) <= urls::detail::to_sv(s1);
1062 }
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074 template<class S0, class S1>
1075 BOOST_CXX14_CONSTEXPR friend auto operator>(
1076 S0 const& s0, S1 const& s1) noexcept ->
1077 typename std::enable_if<
1078 is_match<S0, S1>::value, bool>::type
1079 {
1080 return urls::detail::to_sv(s0) > urls::detail::to_sv(s1);
1081 }
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093 template<class S0, class S1>
1094 BOOST_CXX14_CONSTEXPR friend auto operator>=(
1095 S0 const& s0, S1 const& s1) noexcept ->
1096 typename std::enable_if<
1097 is_match<S0, S1>::value, bool>::type
1098 {
1099 return urls::detail::to_sv(s0) >= urls::detail::to_sv(s1);
1100 }
1101 #endif
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111 BOOST_URL_DECL
1112 friend
1113 std::ostream&
1114 operator<<(
1115 std::ostream& os,
1116 string_view_base const& s);
1117 };
1118
1119
1120
1121
1122
1123 BOOST_URL_DECL
1124 std::ostream&
1125 operator<<(
1126 std::ostream& os,
1127 string_view_base const& s);
1128
1129 }
1130
1131 #ifndef BOOST_URL_DOCS
1132 namespace detail {
1133 template <>
1134 inline
1135 core::string_view
1136 to_sv(grammar::string_view_base const& s) noexcept
1137 {
1138 return s.operator core::string_view();
1139 }
1140 }
1141 #endif
1142
1143 }
1144 }
1145
1146 #endif