| 
									
										
										
										
											2006-02-14 09:37:26 +00:00
										 |  |  | //  Boost string_algo library split.hpp header file  ---------------------------//
 | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-14 09:37:26 +00:00
										 |  |  | //  Copyright Pavol Droba 2002-2006. Use, modification and
 | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | //  distribution is subject to 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)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  See http://www.boost.org for updates, documentation, and revision history.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef BOOST_STRING_SPLIT_HPP
 | 
					
						
							|  |  |  | #define BOOST_STRING_SPLIT_HPP
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/algorithm/string/config.hpp>
 | 
					
						
							| 
									
										
										
										
											2005-01-21 16:45:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | #include <boost/algorithm/string/iter_find.hpp>
 | 
					
						
							|  |  |  | #include <boost/algorithm/string/finder.hpp>
 | 
					
						
							|  |  |  | #include <boost/algorithm/string/compare.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*! \file
 | 
					
						
							|  |  |  |     Defines basic split algorithms.  | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  |     Split algorithms can be used to divide a string | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |     into several parts according to given criteria. | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     Each part is copied and added as a new element to the | 
					
						
							|  |  |  |     output container. | 
					
						
							|  |  |  |     Thus the result container must be able to hold copies | 
					
						
							|  |  |  |     of the matches (in a compatible structure like std::string) or | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |     a reference to it (e.g. using the iterator range class). | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  |     Examples of such a container are \c std::vector<std::string> | 
					
						
							|  |  |  |     or \c std::list<boost::iterator_range<std::string::iterator>> | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace boost { | 
					
						
							|  |  |  |     namespace algorithm { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  find_all  ------------------------------------------------------------//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Find all algorithm
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  |             This algorithm finds all occurrences of the search string | 
					
						
							|  |  |  |             in the input. | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |             Each part is copied and added as a new element to the | 
					
						
							|  |  |  |             output container. | 
					
						
							|  |  |  |             Thus the result container must be able to hold copies | 
					
						
							|  |  |  |             of the matches (in a compatible structure like std::string) or | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             a reference to it (e.g. using the iterator range class). | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  |             Examples of such a container are \c std::vector<std::string> | 
					
						
							|  |  |  |             or \c std::list<boost::iterator_range<std::string::iterator>> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             \param Result A container that can hold copies of references to the substrings | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             \param Input A container which will be searched. | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             \param Search A substring to be searched for. | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             \return A reference the result | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             \note Prior content of the result will be overwritten. | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-14 09:37:26 +00:00
										 |  |  |             \note 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 SequenceSequenceT, typename Range1T, typename Range2T > | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         inline SequenceSequenceT& find_all( | 
					
						
							|  |  |  |             SequenceSequenceT& Result, | 
					
						
							| 
									
										
										
										
											2005-04-12 16:50:42 +00:00
										 |  |  |             Range1T& Input, | 
					
						
							|  |  |  |             const Range2T& Search) | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |             return iter_find( | 
					
						
							|  |  |  |                 Result, | 
					
						
							|  |  |  |                 Input, | 
					
						
							|  |  |  |                 first_finder(Search) );         | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Find all algorithm ( case insensitive ) 
 | 
					
						
							|  |  |  |         /*!
 | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             This algorithm finds all occurrences of the search string | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  |             in the input.  | 
					
						
							|  |  |  |             Each part is copied and added as a new element to the | 
					
						
							|  |  |  |             output container. Thus the result container must be able to hold copies | 
					
						
							|  |  |  |             of the matches (in a compatible structure like std::string) or | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             a reference to it (e.g. using the iterator range class). | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  |             Examples of such a container are \c std::vector<std::string> | 
					
						
							|  |  |  |             or \c std::list<boost::iterator_range<std::string::iterator>> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             Searching is case insensitive. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             \param Result A container that can hold copies of references to the substrings | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             \param Input A container which will be searched. | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             \param Search A substring to be searched for. | 
					
						
							|  |  |  |             \param Loc A locale used for case insensitive comparison | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             \return A reference the result | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             \note Prior content of the result will be overwritten. | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-14 09:37:26 +00:00
										 |  |  |             \note 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 SequenceSequenceT, typename Range1T, typename Range2T > | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         inline SequenceSequenceT& ifind_all( | 
					
						
							|  |  |  |             SequenceSequenceT& Result, | 
					
						
							| 
									
										
										
										
											2005-04-12 16:50:42 +00:00
										 |  |  |             Range1T& Input, | 
					
						
							|  |  |  |             const Range2T& Search, | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             const std::locale& Loc=std::locale() ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return iter_find( | 
					
						
							|  |  |  |                 Result, | 
					
						
							|  |  |  |                 Input, | 
					
						
							|  |  |  |                 first_finder(Search, is_iequal(Loc) ) );         | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  tokenize  -------------------------------------------------------------//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //! Split algorithm
 | 
					
						
							|  |  |  |         /*! 
 | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             Tokenize expression. This function is equivalent to C strtok. Input | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             sequence is split into tokens, separated by separators. Separators  | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             are given by means of the predicate. | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  |             Each part is copied and added as a new element to the | 
					
						
							|  |  |  |             output container. | 
					
						
							|  |  |  |             Thus the result container must be able to hold copies | 
					
						
							|  |  |  |             of the matches (in a compatible structure like std::string) or | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             a reference to it (e.g. using the iterator range class). | 
					
						
							| 
									
										
										
										
											2004-07-14 21:28:31 +00:00
										 |  |  |             Examples of such a container are \c std::vector<std::string> | 
					
						
							|  |  |  |             or \c std::list<boost::iterator_range<std::string::iterator>> | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |             \param Result A container that can hold copies of references to the substrings           | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             \param Input A container which will be searched. | 
					
						
							|  |  |  |             \param Pred A predicate to identify separators. This predicate is  | 
					
						
							|  |  |  |                 supposed to return true if a given element is a separator. | 
					
						
							|  |  |  |             \param eCompress If eCompress argument is set to token_compress_on, adjacent  | 
					
						
							|  |  |  |                 separators are merged together. Otherwise, every two separators | 
					
						
							|  |  |  |                 delimit a token. | 
					
						
							|  |  |  |             \return A reference the result | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-15 21:48:25 +00:00
										 |  |  |             \note Prior content of the result will be overwritten. | 
					
						
							| 
									
										
										
										
											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
										 |  |  |         */ | 
					
						
							| 
									
										
										
										
											2005-04-12 16:50:42 +00:00
										 |  |  |         template< typename SequenceSequenceT, typename RangeT, typename PredicateT > | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |         inline SequenceSequenceT& split( | 
					
						
							|  |  |  |             SequenceSequenceT& Result, | 
					
						
							| 
									
										
										
										
											2005-04-12 16:50:42 +00:00
										 |  |  |             RangeT& Input, | 
					
						
							| 
									
										
										
										
											2004-03-04 22:12:19 +00:00
										 |  |  |             PredicateT Pred, | 
					
						
							|  |  |  |             token_compress_mode_type eCompress=token_compress_off ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return iter_split( | 
					
						
							|  |  |  |                 Result, | 
					
						
							|  |  |  |                 Input, | 
					
						
							|  |  |  |                 token_finder( Pred, eCompress ) );          | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } // namespace algorithm
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // pull names to the boost namespace
 | 
					
						
							|  |  |  |     using algorithm::find_all; | 
					
						
							|  |  |  |     using algorithm::ifind_all; | 
					
						
							|  |  |  |     using algorithm::split;     | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace boost
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif  // BOOST_STRING_SPLIT_HPP
 | 
					
						
							|  |  |  | 
 |