File indexing completed on 2025-02-22 09:55:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_STRING_TRIM_HPP
0012 #define BOOST_STRING_TRIM_HPP
0013
0014 #include <boost/algorithm/string/config.hpp>
0015
0016 #include <boost/range/begin.hpp>
0017 #include <boost/range/end.hpp>
0018 #include <boost/range/const_iterator.hpp>
0019 #include <boost/range/as_literal.hpp>
0020 #include <boost/range/iterator_range_core.hpp>
0021
0022 #include <boost/algorithm/string/detail/trim.hpp>
0023 #include <boost/algorithm/string/classification.hpp>
0024 #include <locale>
0025
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
0058
0059
0060 template<typename OutputIteratorT, typename RangeT, typename PredicateT>
0061 inline OutputIteratorT trim_left_copy_if(
0062 OutputIteratorT Output,
0063 const RangeT& Input,
0064 PredicateT IsSpace)
0065 {
0066 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_range(::boost::as_literal(Input));
0067
0068 std::copy(
0069 ::boost::algorithm::detail::trim_begin(
0070 ::boost::begin(lit_range),
0071 ::boost::end(lit_range),
0072 IsSpace ),
0073 ::boost::end(lit_range),
0074 Output);
0075
0076 return Output;
0077 }
0078
0079
0080
0081
0082
0083 template<typename SequenceT, typename PredicateT>
0084 inline SequenceT trim_left_copy_if(const SequenceT& Input, PredicateT IsSpace)
0085 {
0086 return SequenceT(
0087 ::boost::algorithm::detail::trim_begin(
0088 ::boost::begin(Input),
0089 ::boost::end(Input),
0090 IsSpace ),
0091 ::boost::end(Input));
0092 }
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 template<typename SequenceT>
0106 inline SequenceT trim_left_copy(const SequenceT& Input, const std::locale& Loc=std::locale())
0107 {
0108 return
0109 ::boost::algorithm::trim_left_copy_if(
0110 Input,
0111 is_space(Loc));
0112 }
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 template<typename SequenceT, typename PredicateT>
0124 inline void trim_left_if(SequenceT& Input, PredicateT IsSpace)
0125 {
0126 Input.erase(
0127 ::boost::begin(Input),
0128 ::boost::algorithm::detail::trim_begin(
0129 ::boost::begin(Input),
0130 ::boost::end(Input),
0131 IsSpace));
0132 }
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142 template<typename SequenceT>
0143 inline void trim_left(SequenceT& Input, const std::locale& Loc=std::locale())
0144 {
0145 ::boost::algorithm::trim_left_if(
0146 Input,
0147 is_space(Loc));
0148 }
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 template<typename OutputIteratorT, typename RangeT, typename PredicateT>
0169 inline OutputIteratorT trim_right_copy_if(
0170 OutputIteratorT Output,
0171 const RangeT& Input,
0172 PredicateT IsSpace )
0173 {
0174 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_range(::boost::as_literal(Input));
0175
0176 std::copy(
0177 ::boost::begin(lit_range),
0178 ::boost::algorithm::detail::trim_end(
0179 ::boost::begin(lit_range),
0180 ::boost::end(lit_range),
0181 IsSpace ),
0182 Output );
0183
0184 return Output;
0185 }
0186
0187
0188
0189
0190
0191 template<typename SequenceT, typename PredicateT>
0192 inline SequenceT trim_right_copy_if(const SequenceT& Input, PredicateT IsSpace)
0193 {
0194 return SequenceT(
0195 ::boost::begin(Input),
0196 ::boost::algorithm::detail::trim_end(
0197 ::boost::begin(Input),
0198 ::boost::end(Input),
0199 IsSpace)
0200 );
0201 }
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214 template<typename SequenceT>
0215 inline SequenceT trim_right_copy(const SequenceT& Input, const std::locale& Loc=std::locale())
0216 {
0217 return
0218 ::boost::algorithm::trim_right_copy_if(
0219 Input,
0220 is_space(Loc));
0221 }
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233 template<typename SequenceT, typename PredicateT>
0234 inline void trim_right_if(SequenceT& Input, PredicateT IsSpace)
0235 {
0236 Input.erase(
0237 ::boost::algorithm::detail::trim_end(
0238 ::boost::begin(Input),
0239 ::boost::end(Input),
0240 IsSpace ),
0241 ::boost::end(Input)
0242 );
0243 }
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254 template<typename SequenceT>
0255 inline void trim_right(SequenceT& Input, const std::locale& Loc=std::locale())
0256 {
0257 ::boost::algorithm::trim_right_if(
0258 Input,
0259 is_space(Loc) );
0260 }
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280 template<typename OutputIteratorT, typename RangeT, typename PredicateT>
0281 inline OutputIteratorT trim_copy_if(
0282 OutputIteratorT Output,
0283 const RangeT& Input,
0284 PredicateT IsSpace)
0285 {
0286 iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_range(::boost::as_literal(Input));
0287
0288 BOOST_STRING_TYPENAME
0289 range_const_iterator<RangeT>::type TrimEnd=
0290 ::boost::algorithm::detail::trim_end(
0291 ::boost::begin(lit_range),
0292 ::boost::end(lit_range),
0293 IsSpace);
0294
0295 std::copy(
0296 detail::trim_begin(
0297 ::boost::begin(lit_range), TrimEnd, IsSpace),
0298 TrimEnd,
0299 Output
0300 );
0301
0302 return Output;
0303 }
0304
0305
0306
0307
0308
0309 template<typename SequenceT, typename PredicateT>
0310 inline SequenceT trim_copy_if(const SequenceT& Input, PredicateT IsSpace)
0311 {
0312 BOOST_STRING_TYPENAME
0313 range_const_iterator<SequenceT>::type TrimEnd=
0314 ::boost::algorithm::detail::trim_end(
0315 ::boost::begin(Input),
0316 ::boost::end(Input),
0317 IsSpace);
0318
0319 return SequenceT(
0320 detail::trim_begin(
0321 ::boost::begin(Input),
0322 TrimEnd,
0323 IsSpace),
0324 TrimEnd
0325 );
0326 }
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339 template<typename SequenceT>
0340 inline SequenceT trim_copy( const SequenceT& Input, const std::locale& Loc=std::locale() )
0341 {
0342 return
0343 ::boost::algorithm::trim_copy_if(
0344 Input,
0345 is_space(Loc) );
0346 }
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357 template<typename SequenceT, typename PredicateT>
0358 inline void trim_if(SequenceT& Input, PredicateT IsSpace)
0359 {
0360 ::boost::algorithm::trim_right_if( Input, IsSpace );
0361 ::boost::algorithm::trim_left_if( Input, IsSpace );
0362 }
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372 template<typename SequenceT>
0373 inline void trim(SequenceT& Input, const std::locale& Loc=std::locale())
0374 {
0375 ::boost::algorithm::trim_if(
0376 Input,
0377 is_space( Loc ) );
0378 }
0379
0380 }
0381
0382
0383 using algorithm::trim_left;
0384 using algorithm::trim_left_if;
0385 using algorithm::trim_left_copy;
0386 using algorithm::trim_left_copy_if;
0387 using algorithm::trim_right;
0388 using algorithm::trim_right_if;
0389 using algorithm::trim_right_copy;
0390 using algorithm::trim_right_copy_if;
0391 using algorithm::trim;
0392 using algorithm::trim_if;
0393 using algorithm::trim_copy;
0394 using algorithm::trim_copy_if;
0395
0396 }
0397
0398 #endif