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