| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | //  Boost string_algo library trim.hpp header file  ---------------------------//
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-25 18:07:19 +00:00
										 |  |  | //  Copyright Pavol Droba 2002-2003.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Distributed under the Boost Software License, Version 1.0.
 | 
					
						
							|  |  |  | //    (See accompanying file LICENSE_1_0.txt or copy at
 | 
					
						
							|  |  |  | //          http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-25 18:07:19 +00:00
										 |  |  | //  See http://www.boost.org/ for updates, documentation, and revision history.
 | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifndef BOOST_STRING_TRIM_HPP
 | 
					
						
							|  |  |  | #define BOOST_STRING_TRIM_HPP
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/algorithm/string/config.hpp>
 | 
					
						
							| 
									
										
										
										
											2005-01-21 16:45:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <boost/range/begin.hpp>
 | 
					
						
							|  |  |  | #include <boost/range/end.hpp>
 | 
					
						
							|  |  |  | #include <boost/range/const_iterator.hpp>
 | 
					
						
							| 
									
										
										
										
											2007-11-25 18:07:19 +00:00
										 |  |  | #include <boost/range/as_literal.hpp>
 | 
					
						
							|  |  |  | #include <boost/range/iterator_range.hpp>
 | 
					
						
							| 
									
										
										
										
											2005-01-21 16:45:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | #include <boost/algorithm/string/detail/trim.hpp>
 | 
					
						
							|  |  |  | #include <boost/algorithm/string/classification.hpp>
 | 
					
						
							|  |  |  | #include <locale>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \file
 | 
					
						
							|  |  |  |     Defines trim algorithms. | 
					
						
							|  |  |  |     Trim algorithms are used to remove trailing and leading spaces from a  | 
					
						
							|  |  |  |     sequence (string). Space is recognized using given locales. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |     Parametric (\c _if) variants use a predicate (functor) to select which characters | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |     are to be trimmed..  | 
					
						
							|  |  |  |     Functions take a selection predicate as a parameter, which is used to determine  | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |     whether a character is a space. Common predicates are provided in classification.hpp header. | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace boost { | 
					
						
							|  |  |  |     namespace algorithm { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //  left trim  -----------------------------------------------//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Left trim - parametric
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             Remove all leading spaces from the input.  | 
					
						
							| 
									
										
										
										
											2004-07-16 09:06:39 +00:00
										 |  |  |             The supplied predicate is used to determine which characters are considered spaces. | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |             The result is a trimmed copy of the input. It is returned as a sequence  | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             or copied to the output iterator | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             \param Output An output iterator to which the result will be copied | 
					
						
							| 
									
										
										
										
											2005-05-14 19:09:13 +00:00
										 |  |  |             \param Input An input range | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             \param IsSpace An unary predicate identifying spaces | 
					
						
							| 
									
										
										
										
											2004-07-06 21:28:01 +00:00
										 |  |  |             \return  | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |                 An output iterator pointing just after the last inserted character or | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |                 a copy of the input | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-16 09:06:39 +00:00
										 |  |  |                \note The second variant of this function provides the strong exception-safety guarantee | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         */ | 
					
						
							| 
									
										
										
										
											2005-04-12 16:50:42 +00:00
										 |  |  |         template<typename OutputIteratorT, typename RangeT, typename PredicateT> | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         inline OutputIteratorT trim_left_copy_if(  | 
					
						
							|  |  |  |             OutputIteratorT Output, | 
					
						
							| 
									
										
										
										
											2005-04-12 16:50:42 +00:00
										 |  |  |             const RangeT& Input, | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             PredicateT IsSpace) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2009-09-13 19:10:55 +00:00
										 |  |  |             iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_range(::boost::as_literal(Input)); | 
					
						
							| 
									
										
										
										
											2007-11-25 18:07:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             std::copy(  | 
					
						
							| 
									
										
										
										
											2005-06-06 20:03:18 +00:00
										 |  |  |                 ::boost::algorithm::detail::trim_begin(  | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                     ::boost::begin(lit_range),  | 
					
						
							|  |  |  |                     ::boost::end(lit_range),  | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                     IsSpace ), | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                 ::boost::end(lit_range), | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                 Output); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return Output; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Left trim - parametric
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |             \overload | 
					
						
							|  |  |  |         */ | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         template<typename SequenceT, typename PredicateT> | 
					
						
							|  |  |  |         inline SequenceT trim_left_copy_if(const SequenceT& Input, PredicateT IsSpace) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return SequenceT(  | 
					
						
							| 
									
										
										
										
											2005-06-06 20:03:18 +00:00
										 |  |  |                 ::boost::algorithm::detail::trim_begin(  | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                     ::boost::begin(Input),  | 
					
						
							|  |  |  |                     ::boost::end(Input),  | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                     IsSpace ), | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                 ::boost::end(Input)); | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Left trim - parametric
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							|  |  |  |             Remove all leading spaces from the input.  | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |             The result is a trimmed copy of the input. | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             \param Input An input sequence | 
					
						
							|  |  |  |             \param Loc a locale used for 'space' classification | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |             \return A trimmed copy of the input | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-16 09:06:39 +00:00
										 |  |  |             \note This function provides the strong exception-safety guarantee | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         */ | 
					
						
							|  |  |  |         template<typename SequenceT> | 
					
						
							|  |  |  |         inline SequenceT trim_left_copy(const SequenceT& Input, const std::locale& Loc=std::locale()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return             | 
					
						
							| 
									
										
										
										
											2009-09-13 19:10:55 +00:00
										 |  |  |                 ::boost::algorithm::trim_left_copy_if( | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                     Input,  | 
					
						
							|  |  |  |                     is_space(Loc)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Left trim
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							| 
									
										
										
										
											2004-07-16 09:06:39 +00:00
										 |  |  |             Remove all leading spaces from the input. The supplied predicate is  | 
					
						
							|  |  |  |             used to determine which characters are considered spaces. | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             The input sequence is modified in-place. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             \param Input An input sequence | 
					
						
							|  |  |  |             \param IsSpace An unary predicate identifying spaces | 
					
						
							|  |  |  |         */ | 
					
						
							|  |  |  |         template<typename SequenceT, typename PredicateT> | 
					
						
							|  |  |  |         inline void trim_left_if(SequenceT& Input, PredicateT IsSpace) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             Input.erase(  | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                 ::boost::begin(Input), | 
					
						
							| 
									
										
										
										
											2005-06-06 20:03:18 +00:00
										 |  |  |                 ::boost::algorithm::detail::trim_begin(  | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                     ::boost::begin(Input),  | 
					
						
							|  |  |  |                     ::boost::end(Input),  | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                     IsSpace)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Left trim
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							|  |  |  |             Remove all leading spaces from the input. | 
					
						
							|  |  |  |             The Input sequence is modified in-place. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             \param Input An input sequence | 
					
						
							|  |  |  |             \param Loc A locale used for 'space' classification | 
					
						
							|  |  |  |         */ | 
					
						
							|  |  |  |         template<typename SequenceT> | 
					
						
							|  |  |  |         inline void trim_left(SequenceT& Input, const std::locale& Loc=std::locale()) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2009-09-13 19:10:55 +00:00
										 |  |  |             ::boost::algorithm::trim_left_if(  | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                 Input,  | 
					
						
							|  |  |  |                 is_space(Loc)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //  right trim  -----------------------------------------------//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Right trim - parametric
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							| 
									
										
										
										
											2004-07-16 09:06:39 +00:00
										 |  |  |             Remove all trailing spaces from the input.              | 
					
						
							|  |  |  |             The supplied predicate is used to determine which characters are considered spaces. | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |             The result is a trimmed copy of the input. It is returned as a sequence  | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             or copied to the output iterator | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             \param Output An output iterator to which the result will be copied | 
					
						
							| 
									
										
										
										
											2005-05-14 19:09:13 +00:00
										 |  |  |             \param Input An input range | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             \param IsSpace An unary predicate identifying spaces | 
					
						
							| 
									
										
										
										
											2004-07-06 21:28:01 +00:00
										 |  |  |             \return  | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |                 An output iterator pointing just after the last inserted character or | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |                 a copy of the input | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-16 09:06:39 +00:00
										 |  |  |              \note The second variant of this function provides the strong exception-safety guarantee | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         */ | 
					
						
							| 
									
										
										
										
											2005-04-12 16:50:42 +00:00
										 |  |  |         template<typename OutputIteratorT, typename RangeT, typename PredicateT> | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         inline OutputIteratorT trim_right_copy_if(  | 
					
						
							|  |  |  |             OutputIteratorT Output, | 
					
						
							| 
									
										
										
										
											2005-04-12 16:50:42 +00:00
										 |  |  |             const RangeT& Input, | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             PredicateT IsSpace ) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2009-09-13 19:10:55 +00:00
										 |  |  |             iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_range(::boost::as_literal(Input)); | 
					
						
							| 
									
										
										
										
											2007-11-25 18:07:19 +00:00
										 |  |  |           | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             std::copy(  | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                 ::boost::begin(lit_range), | 
					
						
							| 
									
										
										
										
											2005-06-06 20:03:18 +00:00
										 |  |  |                 ::boost::algorithm::detail::trim_end(  | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                     ::boost::begin(lit_range),  | 
					
						
							|  |  |  |                     ::boost::end(lit_range),  | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                     IsSpace ), | 
					
						
							|  |  |  |                 Output ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return Output; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Right trim - parametric
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |             \overload | 
					
						
							| 
									
										
										
										
											2004-07-06 21:28:01 +00:00
										 |  |  |          */ | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         template<typename SequenceT, typename PredicateT> | 
					
						
							|  |  |  |         inline SequenceT trim_right_copy_if(const SequenceT& Input, PredicateT IsSpace) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return SequenceT(  | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                 ::boost::begin(Input), | 
					
						
							| 
									
										
										
										
											2005-06-06 20:03:18 +00:00
										 |  |  |                 ::boost::algorithm::detail::trim_end(  | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                     ::boost::begin(Input),  | 
					
						
							|  |  |  |                     ::boost::end(Input),  | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                     IsSpace) | 
					
						
							|  |  |  |                 ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Right trim
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							|  |  |  |             Remove all trailing spaces from the input.  | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |             The result is a trimmed copy of the input | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             \param Input An input sequence | 
					
						
							|  |  |  |             \param Loc A locale used for 'space' classification | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |             \return A trimmed copy of the input | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-16 09:06:39 +00:00
										 |  |  |             \note This function provides the strong exception-safety guarantee | 
					
						
							|  |  |  |         */ | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         template<typename SequenceT> | 
					
						
							|  |  |  |         inline SequenceT trim_right_copy(const SequenceT& Input, const std::locale& Loc=std::locale()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return  | 
					
						
							| 
									
										
										
										
											2009-09-13 19:10:55 +00:00
										 |  |  |                 ::boost::algorithm::trim_right_copy_if(  | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                     Input,  | 
					
						
							|  |  |  |                     is_space(Loc)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |         //! Right trim - parametric
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							| 
									
										
										
										
											2004-07-16 09:06:39 +00:00
										 |  |  |             Remove all trailing spaces from the input. | 
					
						
							|  |  |  |             The supplied predicate is used to determine which characters are considered spaces. | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             The input sequence is modified in-place. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             \param Input An input sequence | 
					
						
							|  |  |  |             \param IsSpace An unary predicate identifying spaces | 
					
						
							|  |  |  |         */ | 
					
						
							|  |  |  |         template<typename SequenceT, typename PredicateT> | 
					
						
							|  |  |  |         inline void trim_right_if(SequenceT& Input, PredicateT IsSpace) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             Input.erase( | 
					
						
							| 
									
										
										
										
											2005-06-06 20:03:18 +00:00
										 |  |  |                 ::boost::algorithm::detail::trim_end(  | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                     ::boost::begin(Input),  | 
					
						
							|  |  |  |                     ::boost::end(Input),  | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                     IsSpace ), | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                 ::boost::end(Input) | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                 ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Right trim
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							|  |  |  |             Remove all trailing spaces from the input.  | 
					
						
							|  |  |  |             The input sequence is modified in-place. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             \param Input An input sequence | 
					
						
							|  |  |  |             \param Loc A locale used for 'space' classification | 
					
						
							|  |  |  |         */ | 
					
						
							|  |  |  |         template<typename SequenceT> | 
					
						
							|  |  |  |         inline void trim_right(SequenceT& Input, const std::locale& Loc=std::locale()) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2009-09-13 19:10:55 +00:00
										 |  |  |             ::boost::algorithm::trim_right_if( | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                 Input,  | 
					
						
							|  |  |  |                 is_space(Loc) ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //  both side trim  -----------------------------------------------//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Trim - parametric
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							|  |  |  |             Remove all trailing and leading spaces from the input.  | 
					
						
							| 
									
										
										
										
											2004-07-16 09:06:39 +00:00
										 |  |  |             The supplied predicate is used to determine which characters are considered spaces. | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |             The result is a trimmed copy of the input. It is returned as a sequence  | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             or copied to the output iterator | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             \param Output An output iterator to which the result will be copied | 
					
						
							| 
									
										
										
										
											2005-05-14 19:09:13 +00:00
										 |  |  |             \param Input An input range | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             \param IsSpace An unary predicate identifying spaces | 
					
						
							| 
									
										
										
										
											2004-07-06 21:28:01 +00:00
										 |  |  |             \return  | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |                 An output iterator pointing just after the last inserted character or | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |                 a copy of the input | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-16 09:06:39 +00:00
										 |  |  |              \note The second variant of this function provides the strong exception-safety guarantee | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         */ | 
					
						
							| 
									
										
										
										
											2005-04-12 16:50:42 +00:00
										 |  |  |         template<typename OutputIteratorT, typename RangeT, typename PredicateT> | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         inline OutputIteratorT trim_copy_if(  | 
					
						
							|  |  |  |             OutputIteratorT Output, | 
					
						
							| 
									
										
										
										
											2005-04-12 16:50:42 +00:00
										 |  |  |             const RangeT& Input, | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             PredicateT IsSpace) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2009-09-13 19:10:55 +00:00
										 |  |  |             iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_range(::boost::as_literal(Input)); | 
					
						
							| 
									
										
										
										
											2007-11-25 18:07:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             BOOST_STRING_TYPENAME  | 
					
						
							| 
									
										
										
										
											2005-04-12 16:50:42 +00:00
										 |  |  |                 range_const_iterator<RangeT>::type TrimEnd= | 
					
						
							| 
									
										
										
										
											2005-06-06 20:03:18 +00:00
										 |  |  |                 ::boost::algorithm::detail::trim_end(  | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                     ::boost::begin(lit_range),  | 
					
						
							|  |  |  |                     ::boost::end(lit_range),  | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                     IsSpace); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             std::copy(  | 
					
						
							|  |  |  |                 detail::trim_begin(  | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                     ::boost::begin(lit_range), TrimEnd, IsSpace), | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                 TrimEnd, | 
					
						
							|  |  |  |                 Output | 
					
						
							|  |  |  |                 ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return Output; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Trim - parametric
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |             \overload | 
					
						
							| 
									
										
										
										
											2004-07-06 21:28:01 +00:00
										 |  |  |          */ | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         template<typename SequenceT, typename PredicateT> | 
					
						
							|  |  |  |         inline SequenceT trim_copy_if(const SequenceT& Input, PredicateT IsSpace) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             BOOST_STRING_TYPENAME  | 
					
						
							| 
									
										
										
										
											2005-01-21 16:45:29 +00:00
										 |  |  |                 range_const_iterator<SequenceT>::type TrimEnd= | 
					
						
							| 
									
										
										
										
											2005-06-06 20:03:18 +00:00
										 |  |  |                     ::boost::algorithm::detail::trim_end(  | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                         ::boost::begin(Input),  | 
					
						
							|  |  |  |                         ::boost::end(Input),  | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                         IsSpace); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return SequenceT(  | 
					
						
							|  |  |  |                 detail::trim_begin(  | 
					
						
							| 
									
										
										
										
											2008-06-19 12:07:24 +00:00
										 |  |  |                     ::boost::begin(Input),  | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                     TrimEnd,  | 
					
						
							|  |  |  |                     IsSpace), | 
					
						
							|  |  |  |                 TrimEnd | 
					
						
							|  |  |  |                 ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Trim
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							|  |  |  |             Remove all leading and trailing spaces from the input.  | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |             The result is a trimmed copy of the input | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             \param Input An input sequence | 
					
						
							|  |  |  |             \param Loc A locale used for 'space' classification | 
					
						
							| 
									
										
										
										
											2004-07-11 22:07:00 +00:00
										 |  |  |             \return A trimmed copy of the input | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-16 09:06:39 +00:00
										 |  |  |             \note This function provides the strong exception-safety guarantee | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         */ | 
					
						
							|  |  |  |         template<typename SequenceT> | 
					
						
							|  |  |  |         inline SequenceT trim_copy( const SequenceT& Input, const std::locale& Loc=std::locale() ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return | 
					
						
							| 
									
										
										
										
											2009-09-13 19:10:55 +00:00
										 |  |  |                 ::boost::algorithm::trim_copy_if( | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                     Input,  | 
					
						
							|  |  |  |                     is_space(Loc) ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       | 
					
						
							|  |  |  |         //! Trim
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							|  |  |  |             Remove all leading and trailing spaces from the input.  | 
					
						
							| 
									
										
										
										
											2004-07-16 09:06:39 +00:00
										 |  |  |             The supplied predicate is used to determine which characters are considered spaces. | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             The input sequence is modified in-place. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             \param Input An input sequence | 
					
						
							|  |  |  |             \param IsSpace An unary predicate identifying spaces | 
					
						
							|  |  |  |         */ | 
					
						
							|  |  |  |         template<typename SequenceT, typename PredicateT> | 
					
						
							|  |  |  |         inline void trim_if(SequenceT& Input, PredicateT IsSpace) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2009-09-13 19:10:55 +00:00
										 |  |  |             ::boost::algorithm::trim_right_if( Input, IsSpace ); | 
					
						
							|  |  |  |             ::boost::algorithm::trim_left_if( Input, IsSpace ); | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Trim
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							|  |  |  |             Remove all leading and trailing spaces from the input.  | 
					
						
							|  |  |  |             The input sequence is modified in-place. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             \param Input An input sequence | 
					
						
							|  |  |  |             \param Loc A locale used for 'space' classification | 
					
						
							|  |  |  |         */ | 
					
						
							|  |  |  |         template<typename SequenceT> | 
					
						
							|  |  |  |         inline void trim(SequenceT& Input, const std::locale& Loc=std::locale()) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2009-09-13 19:10:55 +00:00
										 |  |  |             ::boost::algorithm::trim_if( | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |                 Input,  | 
					
						
							|  |  |  |                 is_space( Loc ) ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } // namespace algorithm 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // pull names to the boost namespace
 | 
					
						
							|  |  |  |     using algorithm::trim_left; | 
					
						
							|  |  |  |     using algorithm::trim_left_if; | 
					
						
							|  |  |  |     using algorithm::trim_left_copy; | 
					
						
							|  |  |  |     using algorithm::trim_left_copy_if; | 
					
						
							|  |  |  |     using algorithm::trim_right; | 
					
						
							|  |  |  |     using algorithm::trim_right_if; | 
					
						
							|  |  |  |     using algorithm::trim_right_copy; | 
					
						
							|  |  |  |     using algorithm::trim_right_copy_if; | 
					
						
							|  |  |  |     using algorithm::trim; | 
					
						
							|  |  |  |     using algorithm::trim_if; | 
					
						
							|  |  |  |     using algorithm::trim_copy; | 
					
						
							|  |  |  |     using algorithm::trim_copy_if; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace boost
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif  // BOOST_STRING_TRIM_HPP
 |