Chris@16
|
1 // Boost string_algo library split.hpp header file ---------------------------//
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright Pavol Droba 2002-2006.
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8
|
Chris@16
|
9 // See http://www.boost.org/ for updates, documentation, and revision history.
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_STRING_SPLIT_HPP
|
Chris@16
|
12 #define BOOST_STRING_SPLIT_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/algorithm/string/config.hpp>
|
Chris@16
|
15
|
Chris@16
|
16 #include <boost/algorithm/string/iter_find.hpp>
|
Chris@16
|
17 #include <boost/algorithm/string/finder.hpp>
|
Chris@16
|
18 #include <boost/algorithm/string/compare.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 /*! \file
|
Chris@16
|
21 Defines basic split algorithms.
|
Chris@16
|
22 Split algorithms can be used to divide a string
|
Chris@16
|
23 into several parts according to given criteria.
|
Chris@16
|
24
|
Chris@16
|
25 Each part is copied and added as a new element to the
|
Chris@16
|
26 output container.
|
Chris@16
|
27 Thus the result container must be able to hold copies
|
Chris@16
|
28 of the matches (in a compatible structure like std::string) or
|
Chris@16
|
29 a reference to it (e.g. using the iterator range class).
|
Chris@16
|
30 Examples of such a container are \c std::vector<std::string>
|
Chris@16
|
31 or \c std::list<boost::iterator_range<std::string::iterator>>
|
Chris@16
|
32 */
|
Chris@16
|
33
|
Chris@16
|
34 namespace boost {
|
Chris@16
|
35 namespace algorithm {
|
Chris@16
|
36
|
Chris@16
|
37 // find_all ------------------------------------------------------------//
|
Chris@16
|
38
|
Chris@16
|
39 //! Find all algorithm
|
Chris@16
|
40 /*!
|
Chris@16
|
41 This algorithm finds all occurrences of the search string
|
Chris@16
|
42 in the input.
|
Chris@16
|
43
|
Chris@16
|
44 Each part is copied and added as a new element to the
|
Chris@16
|
45 output container.
|
Chris@16
|
46 Thus the result container must be able to hold copies
|
Chris@16
|
47 of the matches (in a compatible structure like std::string) or
|
Chris@16
|
48 a reference to it (e.g. using the iterator range class).
|
Chris@16
|
49 Examples of such a container are \c std::vector<std::string>
|
Chris@16
|
50 or \c std::list<boost::iterator_range<std::string::iterator>>
|
Chris@16
|
51
|
Chris@16
|
52 \param Result A container that can hold copies of references to the substrings
|
Chris@16
|
53 \param Input A container which will be searched.
|
Chris@16
|
54 \param Search A substring to be searched for.
|
Chris@16
|
55 \return A reference the result
|
Chris@16
|
56
|
Chris@16
|
57 \note Prior content of the result will be overwritten.
|
Chris@16
|
58
|
Chris@16
|
59 \note This function provides the strong exception-safety guarantee
|
Chris@16
|
60 */
|
Chris@16
|
61 template< typename SequenceSequenceT, typename Range1T, typename Range2T >
|
Chris@16
|
62 inline SequenceSequenceT& find_all(
|
Chris@16
|
63 SequenceSequenceT& Result,
|
Chris@16
|
64 Range1T& Input,
|
Chris@16
|
65 const Range2T& Search)
|
Chris@16
|
66 {
|
Chris@16
|
67 return ::boost::algorithm::iter_find(
|
Chris@16
|
68 Result,
|
Chris@16
|
69 Input,
|
Chris@16
|
70 ::boost::algorithm::first_finder(Search) );
|
Chris@16
|
71 }
|
Chris@16
|
72
|
Chris@16
|
73 //! Find all algorithm ( case insensitive )
|
Chris@16
|
74 /*!
|
Chris@16
|
75 This algorithm finds all occurrences of the search string
|
Chris@16
|
76 in the input.
|
Chris@16
|
77 Each part is copied and added as a new element to the
|
Chris@16
|
78 output container. Thus the result container must be able to hold copies
|
Chris@16
|
79 of the matches (in a compatible structure like std::string) or
|
Chris@16
|
80 a reference to it (e.g. using the iterator range class).
|
Chris@16
|
81 Examples of such a container are \c std::vector<std::string>
|
Chris@16
|
82 or \c std::list<boost::iterator_range<std::string::iterator>>
|
Chris@16
|
83
|
Chris@16
|
84 Searching is case insensitive.
|
Chris@16
|
85
|
Chris@16
|
86 \param Result A container that can hold copies of references to the substrings
|
Chris@16
|
87 \param Input A container which will be searched.
|
Chris@16
|
88 \param Search A substring to be searched for.
|
Chris@16
|
89 \param Loc A locale used for case insensitive comparison
|
Chris@16
|
90 \return A reference the result
|
Chris@16
|
91
|
Chris@16
|
92 \note Prior content of the result will be overwritten.
|
Chris@16
|
93
|
Chris@16
|
94 \note This function provides the strong exception-safety guarantee
|
Chris@16
|
95 */
|
Chris@16
|
96 template< typename SequenceSequenceT, typename Range1T, typename Range2T >
|
Chris@16
|
97 inline SequenceSequenceT& ifind_all(
|
Chris@16
|
98 SequenceSequenceT& Result,
|
Chris@16
|
99 Range1T& Input,
|
Chris@16
|
100 const Range2T& Search,
|
Chris@16
|
101 const std::locale& Loc=std::locale() )
|
Chris@16
|
102 {
|
Chris@16
|
103 return ::boost::algorithm::iter_find(
|
Chris@16
|
104 Result,
|
Chris@16
|
105 Input,
|
Chris@16
|
106 ::boost::algorithm::first_finder(Search, is_iequal(Loc) ) );
|
Chris@16
|
107 }
|
Chris@16
|
108
|
Chris@16
|
109
|
Chris@16
|
110 // tokenize -------------------------------------------------------------//
|
Chris@16
|
111
|
Chris@16
|
112 //! Split algorithm
|
Chris@16
|
113 /*!
|
Chris@16
|
114 Tokenize expression. This function is equivalent to C strtok. Input
|
Chris@16
|
115 sequence is split into tokens, separated by separators. Separators
|
Chris@16
|
116 are given by means of the predicate.
|
Chris@16
|
117
|
Chris@16
|
118 Each part is copied and added as a new element to the
|
Chris@16
|
119 output container.
|
Chris@16
|
120 Thus the result container must be able to hold copies
|
Chris@16
|
121 of the matches (in a compatible structure like std::string) or
|
Chris@16
|
122 a reference to it (e.g. using the iterator range class).
|
Chris@16
|
123 Examples of such a container are \c std::vector<std::string>
|
Chris@16
|
124 or \c std::list<boost::iterator_range<std::string::iterator>>
|
Chris@16
|
125
|
Chris@16
|
126 \param Result A container that can hold copies of references to the substrings
|
Chris@16
|
127 \param Input A container which will be searched.
|
Chris@16
|
128 \param Pred A predicate to identify separators. This predicate is
|
Chris@16
|
129 supposed to return true if a given element is a separator.
|
Chris@16
|
130 \param eCompress If eCompress argument is set to token_compress_on, adjacent
|
Chris@16
|
131 separators are merged together. Otherwise, every two separators
|
Chris@16
|
132 delimit a token.
|
Chris@16
|
133 \return A reference the result
|
Chris@16
|
134
|
Chris@16
|
135 \note Prior content of the result will be overwritten.
|
Chris@16
|
136
|
Chris@16
|
137 \note This function provides the strong exception-safety guarantee
|
Chris@16
|
138 */
|
Chris@16
|
139 template< typename SequenceSequenceT, typename RangeT, typename PredicateT >
|
Chris@16
|
140 inline SequenceSequenceT& split(
|
Chris@16
|
141 SequenceSequenceT& Result,
|
Chris@16
|
142 RangeT& Input,
|
Chris@16
|
143 PredicateT Pred,
|
Chris@16
|
144 token_compress_mode_type eCompress=token_compress_off )
|
Chris@16
|
145 {
|
Chris@16
|
146 return ::boost::algorithm::iter_split(
|
Chris@16
|
147 Result,
|
Chris@16
|
148 Input,
|
Chris@16
|
149 ::boost::algorithm::token_finder( Pred, eCompress ) );
|
Chris@16
|
150 }
|
Chris@16
|
151
|
Chris@16
|
152 } // namespace algorithm
|
Chris@16
|
153
|
Chris@16
|
154 // pull names to the boost namespace
|
Chris@16
|
155 using algorithm::find_all;
|
Chris@16
|
156 using algorithm::ifind_all;
|
Chris@16
|
157 using algorithm::split;
|
Chris@16
|
158
|
Chris@16
|
159 } // namespace boost
|
Chris@16
|
160
|
Chris@16
|
161
|
Chris@16
|
162 #endif // BOOST_STRING_SPLIT_HPP
|
Chris@16
|
163
|