1 // Boost string_algo library finder.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_FINDER_HPP
12 #define BOOST_STRING_FINDER_HPP
14 #include <boost/algorithm/string/config.hpp>
16 #include <boost/range/iterator_range.hpp>
17 #include <boost/range/begin.hpp>
18 #include <boost/range/end.hpp>
19 #include <boost/range/iterator.hpp>
20 #include <boost/range/const_iterator.hpp>
22 #include <boost/algorithm/string/constants.hpp>
23 #include <boost/algorithm/string/detail/finder.hpp>
24 #include <boost/algorithm/string/compare.hpp>
27 Defines Finder generators. Finder object is a functor which is able to
28 find a substring matching a specific criteria in the input.
29 Finders are used as a pluggable components for replace, find
30 and split facilities. This header contains generator functions
31 for finders provided in this library.
37 // Finder generators ------------------------------------------//
41 Construct the \c first_finder. The finder searches for the first
42 occurrence of the string in a given input.
43 The result is given as an \c iterator_range delimiting the match.
45 \param Search A substring to be searched for.
46 \param Comp An element comparison predicate
47 \return An instance of the \c first_finder object
49 template<typename RangeT>
50 inline detail::first_finderF<
51 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
53 first_finder( const RangeT& Search )
56 detail::first_finderF<
58 range_const_iterator<RangeT>::type,
59 is_equal>( as_literal(Search), is_equal() ) ;
66 template<typename RangeT,typename PredicateT>
67 inline detail::first_finderF<
68 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
71 const RangeT& Search, PredicateT Comp )
74 detail::first_finderF<
76 range_const_iterator<RangeT>::type,
77 PredicateT>( as_literal(Search), Comp );
82 Construct the \c last_finder. The finder searches for the last
83 occurrence of the string in a given input.
84 The result is given as an \c iterator_range delimiting the match.
86 \param Search A substring to be searched for.
87 \param Comp An element comparison predicate
88 \return An instance of the \c last_finder object
90 template<typename RangeT>
91 inline detail::last_finderF<
92 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
94 last_finder( const RangeT& Search )
99 range_const_iterator<RangeT>::type,
100 is_equal>( as_literal(Search), is_equal() );
106 template<typename RangeT, typename PredicateT>
107 inline detail::last_finderF<
108 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
110 last_finder( const RangeT& Search, PredicateT Comp )
113 detail::last_finderF<
114 BOOST_STRING_TYPENAME
115 range_const_iterator<RangeT>::type,
116 PredicateT>( as_literal(Search), Comp ) ;
121 Construct the \c nth_finder. The finder searches for the n-th (zero-indexed)
122 occurrence of the string in a given input.
123 The result is given as an \c iterator_range delimiting the match.
125 \param Search A substring to be searched for.
126 \param Nth An index of the match to be find
127 \param Comp An element comparison predicate
128 \return An instance of the \c nth_finder object
130 template<typename RangeT>
131 inline detail::nth_finderF<
132 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
135 const RangeT& Search,
140 BOOST_STRING_TYPENAME
141 range_const_iterator<RangeT>::type,
142 is_equal>( as_literal(Search), Nth, is_equal() ) ;
148 template<typename RangeT, typename PredicateT>
149 inline detail::nth_finderF<
150 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
153 const RangeT& Search,
159 BOOST_STRING_TYPENAME
160 range_const_iterator<RangeT>::type,
161 PredicateT>( as_literal(Search), Nth, Comp );
166 Construct the \c head_finder. The finder returns a head of a given
167 input. The head is a prefix of a string up to n elements in
168 size. If an input has less then n elements, whole input is
170 The result is given as an \c iterator_range delimiting the match.
172 \param N The size of the head
173 \return An instance of the \c head_finder object
175 inline detail::head_finderF
178 return detail::head_finderF(N);
183 Construct the \c tail_finder. The finder returns a tail of a given
184 input. The tail is a suffix of a string up to n elements in
185 size. If an input has less then n elements, whole input is
187 The result is given as an \c iterator_range delimiting the match.
189 \param N The size of the head
190 \return An instance of the \c tail_finder object
192 inline detail::tail_finderF
195 return detail::tail_finderF(N);
200 Construct the \c token_finder. The finder searches for a token
201 specified by a predicate. It is similar to std::find_if
202 algorithm, with an exception that it return a range of
203 instead of a single iterator.
205 If "compress token mode" is enabled, adjacent matching tokens are
206 concatenated into one match. Thus the finder can be used to
207 search for continuous segments of characters satisfying the
210 The result is given as an \c iterator_range delimiting the match.
212 \param Pred An element selection predicate
213 \param eCompress Compress flag
214 \return An instance of the \c token_finder object
216 template< typename PredicateT >
217 inline detail::token_finderF<PredicateT>
220 token_compress_mode_type eCompress=token_compress_off )
222 return detail::token_finderF<PredicateT>( Pred, eCompress );
227 Construct the \c range_finder. The finder does not perform
228 any operation. It simply returns the given range for
231 \param Begin Beginning of the range
232 \param End End of the range
233 \param Range The range.
234 \return An instance of the \c range_finger object
236 template< typename ForwardIteratorT >
237 inline detail::range_finderF<ForwardIteratorT>
239 ForwardIteratorT Begin,
240 ForwardIteratorT End )
242 return detail::range_finderF<ForwardIteratorT>( Begin, End );
249 template< typename ForwardIteratorT >
250 inline detail::range_finderF<ForwardIteratorT>
251 range_finder( iterator_range<ForwardIteratorT> Range )
253 return detail::range_finderF<ForwardIteratorT>( Range );
256 } // namespace algorithm
258 // pull the names to the boost namespace
259 using algorithm::first_finder;
260 using algorithm::last_finder;
261 using algorithm::nth_finder;
262 using algorithm::head_finder;
263 using algorithm::tail_finder;
264 using algorithm::token_finder;
265 using algorithm::range_finder;
270 #endif // BOOST_STRING_FINDER_HPP