1 // Boost string_algo library split.hpp header file ---------------------------//
3 // Copyright Pavol Droba 2002-2006.
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/ for updates, documentation, and revision history.
11 #ifndef BOOST_STRING_SPLIT_HPP
12 #define BOOST_STRING_SPLIT_HPP
14 #include <boost/algorithm/string/config.hpp>
16 #include <boost/algorithm/string/iter_find.hpp>
17 #include <boost/algorithm/string/finder.hpp>
18 #include <boost/algorithm/string/compare.hpp>
21 Defines basic split algorithms.
22 Split algorithms can be used to divide a string
23 into several parts according to given criteria.
25 Each part is copied and added as a new element to the
27 Thus the result container must be able to hold copies
28 of the matches (in a compatible structure like std::string) or
29 a reference to it (e.g. using the iterator range class).
30 Examples of such a container are \c std::vector<std::string>
31 or \c std::list<boost::iterator_range<std::string::iterator>>
37 // find_all ------------------------------------------------------------//
39 //! Find all algorithm
41 This algorithm finds all occurrences of the search string
44 Each part is copied and added as a new element to the
46 Thus the result container must be able to hold copies
47 of the matches (in a compatible structure like std::string) or
48 a reference to it (e.g. using the iterator range class).
49 Examples of such a container are \c std::vector<std::string>
50 or \c std::list<boost::iterator_range<std::string::iterator>>
52 \param Result A container that can hold copies of references to the substrings
53 \param Input A container which will be searched.
54 \param Search A substring to be searched for.
55 \return A reference the result
57 \note Prior content of the result will be overwritten.
59 \note This function provides the strong exception-safety guarantee
61 template< typename SequenceSequenceT, typename Range1T, typename Range2T >
62 inline SequenceSequenceT& find_all(
63 SequenceSequenceT& Result,
65 const Range2T& Search)
67 return ::boost::algorithm::iter_find(
70 ::boost::algorithm::first_finder(Search) );
73 //! Find all algorithm ( case insensitive )
75 This algorithm finds all occurrences of the search string
77 Each part is copied and added as a new element to the
78 output container. Thus the result container must be able to hold copies
79 of the matches (in a compatible structure like std::string) or
80 a reference to it (e.g. using the iterator range class).
81 Examples of such a container are \c std::vector<std::string>
82 or \c std::list<boost::iterator_range<std::string::iterator>>
84 Searching is case insensitive.
86 \param Result A container that can hold copies of references to the substrings
87 \param Input A container which will be searched.
88 \param Search A substring to be searched for.
89 \param Loc A locale used for case insensitive comparison
90 \return A reference the result
92 \note Prior content of the result will be overwritten.
94 \note This function provides the strong exception-safety guarantee
96 template< typename SequenceSequenceT, typename Range1T, typename Range2T >
97 inline SequenceSequenceT& ifind_all(
98 SequenceSequenceT& Result,
100 const Range2T& Search,
101 const std::locale& Loc=std::locale() )
103 return ::boost::algorithm::iter_find(
106 ::boost::algorithm::first_finder(Search, is_iequal(Loc) ) );
110 // tokenize -------------------------------------------------------------//
114 Tokenize expression. This function is equivalent to C strtok. Input
115 sequence is split into tokens, separated by separators. Separators
116 are given by means of the predicate.
118 Each part is copied and added as a new element to the
120 Thus the result container must be able to hold copies
121 of the matches (in a compatible structure like std::string) or
122 a reference to it (e.g. using the iterator range class).
123 Examples of such a container are \c std::vector<std::string>
124 or \c std::list<boost::iterator_range<std::string::iterator>>
126 \param Result A container that can hold copies of references to the substrings
127 \param Input A container which will be searched.
128 \param Pred A predicate to identify separators. This predicate is
129 supposed to return true if a given element is a separator.
130 \param eCompress If eCompress argument is set to token_compress_on, adjacent
131 separators are merged together. Otherwise, every two separators
133 \return A reference the result
135 \note Prior content of the result will be overwritten.
137 \note This function provides the strong exception-safety guarantee
139 template< typename SequenceSequenceT, typename RangeT, typename PredicateT >
140 inline SequenceSequenceT& split(
141 SequenceSequenceT& Result,
144 token_compress_mode_type eCompress=token_compress_off )
146 return ::boost::algorithm::iter_split(
149 ::boost::algorithm::token_finder( Pred, eCompress ) );
152 } // namespace algorithm
154 // pull names to the boost namespace
155 using algorithm::find_all;
156 using algorithm::ifind_all;
157 using algorithm::split;
162 #endif // BOOST_STRING_SPLIT_HPP