File indexing completed on 2025-02-22 09:55:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_STRING_PREDICATE_HPP
0012 #define BOOST_STRING_PREDICATE_HPP
0013
0014 #include <iterator>
0015 #include <boost/algorithm/string/config.hpp>
0016 #include <boost/range/begin.hpp>
0017 #include <boost/range/end.hpp>
0018 #include <boost/range/iterator.hpp>
0019 #include <boost/range/const_iterator.hpp>
0020 #include <boost/range/as_literal.hpp>
0021 #include <boost/range/iterator_range_core.hpp>
0022
0023 #include <boost/algorithm/string/compare.hpp>
0024 #include <boost/algorithm/string/find.hpp>
0025 #include <boost/algorithm/string/detail/predicate.hpp>
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 namespace boost {
0039 namespace algorithm {
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 template<typename Range1T, typename Range2T, typename PredicateT>
0058 inline bool starts_with(
0059 const Range1T& Input,
0060 const Range2T& Test,
0061 PredicateT Comp)
0062 {
0063 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(::boost::as_literal(Input));
0064 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(::boost::as_literal(Test));
0065
0066 typedef BOOST_STRING_TYPENAME
0067 range_const_iterator<Range1T>::type Iterator1T;
0068 typedef BOOST_STRING_TYPENAME
0069 range_const_iterator<Range2T>::type Iterator2T;
0070
0071 Iterator1T InputEnd=::boost::end(lit_input);
0072 Iterator2T TestEnd=::boost::end(lit_test);
0073
0074 Iterator1T it=::boost::begin(lit_input);
0075 Iterator2T pit=::boost::begin(lit_test);
0076 for(;
0077 it!=InputEnd && pit!=TestEnd;
0078 ++it,++pit)
0079 {
0080 if( !(Comp(*it,*pit)) )
0081 return false;
0082 }
0083
0084 return pit==TestEnd;
0085 }
0086
0087
0088
0089
0090
0091 template<typename Range1T, typename Range2T>
0092 inline bool starts_with(
0093 const Range1T& Input,
0094 const Range2T& Test)
0095 {
0096 return ::boost::algorithm::starts_with(Input, Test, is_equal());
0097 }
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 template<typename Range1T, typename Range2T>
0113 inline bool istarts_with(
0114 const Range1T& Input,
0115 const Range2T& Test,
0116 const std::locale& Loc=std::locale())
0117 {
0118 return ::boost::algorithm::starts_with(Input, Test, is_iequal(Loc));
0119 }
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 template<typename Range1T, typename Range2T, typename PredicateT>
0140 inline bool ends_with(
0141 const Range1T& Input,
0142 const Range2T& Test,
0143 PredicateT Comp)
0144 {
0145 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(::boost::as_literal(Input));
0146 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(::boost::as_literal(Test));
0147
0148 typedef BOOST_STRING_TYPENAME
0149 range_const_iterator<Range1T>::type Iterator1T;
0150 typedef BOOST_STRING_TYPENAME
0151 std::iterator_traits<Iterator1T>::iterator_category category;
0152
0153 return detail::
0154 ends_with_iter_select(
0155 ::boost::begin(lit_input),
0156 ::boost::end(lit_input),
0157 ::boost::begin(lit_test),
0158 ::boost::end(lit_test),
0159 Comp,
0160 category());
0161 }
0162
0163
0164
0165
0166
0167
0168 template<typename Range1T, typename Range2T>
0169 inline bool ends_with(
0170 const Range1T& Input,
0171 const Range2T& Test)
0172 {
0173 return ::boost::algorithm::ends_with(Input, Test, is_equal());
0174 }
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189 template<typename Range1T, typename Range2T>
0190 inline bool iends_with(
0191 const Range1T& Input,
0192 const Range2T& Test,
0193 const std::locale& Loc=std::locale())
0194 {
0195 return ::boost::algorithm::ends_with(Input, Test, is_iequal(Loc));
0196 }
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213 template<typename Range1T, typename Range2T, typename PredicateT>
0214 inline bool contains(
0215 const Range1T& Input,
0216 const Range2T& Test,
0217 PredicateT Comp)
0218 {
0219 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(::boost::as_literal(Input));
0220 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(::boost::as_literal(Test));
0221
0222 if (::boost::empty(lit_test))
0223 {
0224
0225 return true;
0226 }
0227
0228
0229 bool bResult=(::boost::algorithm::first_finder(lit_test,Comp)(::boost::begin(lit_input), ::boost::end(lit_input)));
0230 return bResult;
0231 }
0232
0233
0234
0235
0236
0237 template<typename Range1T, typename Range2T>
0238 inline bool contains(
0239 const Range1T& Input,
0240 const Range2T& Test)
0241 {
0242 return ::boost::algorithm::contains(Input, Test, is_equal());
0243 }
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257 template<typename Range1T, typename Range2T>
0258 inline bool icontains(
0259 const Range1T& Input,
0260 const Range2T& Test,
0261 const std::locale& Loc=std::locale())
0262 {
0263 return ::boost::algorithm::contains(Input, Test, is_iequal(Loc));
0264 }
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284 template<typename Range1T, typename Range2T, typename PredicateT>
0285 inline bool equals(
0286 const Range1T& Input,
0287 const Range2T& Test,
0288 PredicateT Comp)
0289 {
0290 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(::boost::as_literal(Input));
0291 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(::boost::as_literal(Test));
0292
0293 typedef BOOST_STRING_TYPENAME
0294 range_const_iterator<Range1T>::type Iterator1T;
0295 typedef BOOST_STRING_TYPENAME
0296 range_const_iterator<Range2T>::type Iterator2T;
0297
0298 Iterator1T InputEnd=::boost::end(lit_input);
0299 Iterator2T TestEnd=::boost::end(lit_test);
0300
0301 Iterator1T it=::boost::begin(lit_input);
0302 Iterator2T pit=::boost::begin(lit_test);
0303 for(;
0304 it!=InputEnd && pit!=TestEnd;
0305 ++it,++pit)
0306 {
0307 if( !(Comp(*it,*pit)) )
0308 return false;
0309 }
0310
0311 return (pit==TestEnd) && (it==InputEnd);
0312 }
0313
0314
0315
0316
0317
0318 template<typename Range1T, typename Range2T>
0319 inline bool equals(
0320 const Range1T& Input,
0321 const Range2T& Test)
0322 {
0323 return ::boost::algorithm::equals(Input, Test, is_equal());
0324 }
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341 template<typename Range1T, typename Range2T>
0342 inline bool iequals(
0343 const Range1T& Input,
0344 const Range2T& Test,
0345 const std::locale& Loc=std::locale())
0346 {
0347 return ::boost::algorithm::equals(Input, Test, is_iequal(Loc));
0348 }
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370 template<typename Range1T, typename Range2T, typename PredicateT>
0371 inline bool lexicographical_compare(
0372 const Range1T& Arg1,
0373 const Range2T& Arg2,
0374 PredicateT Pred)
0375 {
0376 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_arg1(::boost::as_literal(Arg1));
0377 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_arg2(::boost::as_literal(Arg2));
0378
0379 return std::lexicographical_compare(
0380 ::boost::begin(lit_arg1),
0381 ::boost::end(lit_arg1),
0382 ::boost::begin(lit_arg2),
0383 ::boost::end(lit_arg2),
0384 Pred);
0385 }
0386
0387
0388
0389
0390
0391 template<typename Range1T, typename Range2T>
0392 inline bool lexicographical_compare(
0393 const Range1T& Arg1,
0394 const Range2T& Arg2)
0395 {
0396 return ::boost::algorithm::lexicographical_compare(Arg1, Arg2, is_less());
0397 }
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415 template<typename Range1T, typename Range2T>
0416 inline bool ilexicographical_compare(
0417 const Range1T& Arg1,
0418 const Range2T& Arg2,
0419 const std::locale& Loc=std::locale())
0420 {
0421 return ::boost::algorithm::lexicographical_compare(Arg1, Arg2, is_iless(Loc));
0422 }
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438 template<typename RangeT, typename PredicateT>
0439 inline bool all(
0440 const RangeT& Input,
0441 PredicateT Pred)
0442 {
0443 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_input(::boost::as_literal(Input));
0444
0445 typedef BOOST_STRING_TYPENAME
0446 range_const_iterator<RangeT>::type Iterator1T;
0447
0448 Iterator1T InputEnd=::boost::end(lit_input);
0449 for( Iterator1T It=::boost::begin(lit_input); It!=InputEnd; ++It)
0450 {
0451 if (!Pred(*It))
0452 return false;
0453 }
0454
0455 return true;
0456 }
0457
0458 }
0459
0460
0461 using algorithm::starts_with;
0462 using algorithm::istarts_with;
0463 using algorithm::ends_with;
0464 using algorithm::iends_with;
0465 using algorithm::contains;
0466 using algorithm::icontains;
0467 using algorithm::equals;
0468 using algorithm::iequals;
0469 using algorithm::all;
0470 using algorithm::lexicographical_compare;
0471 using algorithm::ilexicographical_compare;
0472
0473 }
0474
0475
0476 #endif