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_core.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 \return An instance of the \c first_finder object
48 template<typename RangeT>
49 inline detail::first_finderF<
50 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
52 first_finder( const RangeT& Search )
55 detail::first_finderF<
57 range_const_iterator<RangeT>::type,
58 is_equal>( ::boost::as_literal(Search), is_equal() ) ;
65 template<typename RangeT,typename PredicateT>
66 inline detail::first_finderF<
67 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
70 const RangeT& Search, PredicateT Comp )
73 detail::first_finderF<
75 range_const_iterator<RangeT>::type,
76 PredicateT>( ::boost::as_literal(Search), Comp );
81 Construct the \c last_finder. The finder searches for the last
82 occurrence of the string in a given input.
83 The result is given as an \c iterator_range delimiting the match.
85 \param Search A substring to be searched for.
86 \return An instance of the \c last_finder object
88 template<typename RangeT>
89 inline detail::last_finderF<
90 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
92 last_finder( const RangeT& Search )
97 range_const_iterator<RangeT>::type,
98 is_equal>( ::boost::as_literal(Search), is_equal() );
104 template<typename RangeT, typename PredicateT>
105 inline detail::last_finderF<
106 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
108 last_finder( const RangeT& Search, PredicateT Comp )
111 detail::last_finderF<
112 BOOST_STRING_TYPENAME
113 range_const_iterator<RangeT>::type,
114 PredicateT>( ::boost::as_literal(Search), Comp ) ;
119 Construct the \c nth_finder. The finder searches for the n-th (zero-indexed)
120 occurrence of the string in a given input.
121 The result is given as an \c iterator_range delimiting the match.
123 \param Search A substring to be searched for.
124 \param Nth An index of the match to be find
125 \return An instance of the \c nth_finder object
127 template<typename RangeT>
128 inline detail::nth_finderF<
129 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
132 const RangeT& Search,
137 BOOST_STRING_TYPENAME
138 range_const_iterator<RangeT>::type,
139 is_equal>( ::boost::as_literal(Search), Nth, is_equal() ) ;
145 template<typename RangeT, typename PredicateT>
146 inline detail::nth_finderF<
147 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type,
150 const RangeT& Search,
156 BOOST_STRING_TYPENAME
157 range_const_iterator<RangeT>::type,
158 PredicateT>( ::boost::as_literal(Search), Nth, Comp );
163 Construct the \c head_finder. The finder returns a head of a given
164 input. The head is a prefix of a string up to n elements in
165 size. If an input has less then n elements, whole input is
167 The result is given as an \c iterator_range delimiting the match.
169 \param N The size of the head
170 \return An instance of the \c head_finder object
172 inline detail::head_finderF
175 return detail::head_finderF(N);
180 Construct the \c tail_finder. The finder returns a tail of a given
181 input. The tail is a suffix of a string up to n elements in
182 size. If an input has less then n elements, whole input is
184 The result is given as an \c iterator_range delimiting the match.
186 \param N The size of the head
187 \return An instance of the \c tail_finder object
189 inline detail::tail_finderF
192 return detail::tail_finderF(N);
197 Construct the \c token_finder. The finder searches for a token
198 specified by a predicate. It is similar to std::find_if
199 algorithm, with an exception that it return a range of
200 instead of a single iterator.
202 If "compress token mode" is enabled, adjacent matching tokens are
203 concatenated into one match. Thus the finder can be used to
204 search for continuous segments of characters satisfying the
207 The result is given as an \c iterator_range delimiting the match.
209 \param Pred An element selection predicate
210 \param eCompress Compress flag
211 \return An instance of the \c token_finder object
213 template< typename PredicateT >
214 inline detail::token_finderF<PredicateT>
217 token_compress_mode_type eCompress=token_compress_off )
219 return detail::token_finderF<PredicateT>( Pred, eCompress );
224 Construct the \c range_finder. The finder does not perform
225 any operation. It simply returns the given range for
228 \param Begin Beginning of the range
229 \param End End of the range
230 \return An instance of the \c range_finger object
232 template< typename ForwardIteratorT >
233 inline detail::range_finderF<ForwardIteratorT>
235 ForwardIteratorT Begin,
236 ForwardIteratorT End )
238 return detail::range_finderF<ForwardIteratorT>( Begin, End );
245 template< typename ForwardIteratorT >
246 inline detail::range_finderF<ForwardIteratorT>
247 range_finder( iterator_range<ForwardIteratorT> Range )
249 return detail::range_finderF<ForwardIteratorT>( Range );
252 } // namespace algorithm
254 // pull the names to the boost namespace
255 using algorithm::first_finder;
256 using algorithm::last_finder;
257 using algorithm::nth_finder;
258 using algorithm::head_finder;
259 using algorithm::tail_finder;
260 using algorithm::token_finder;
261 using algorithm::range_finder;
266 #endif // BOOST_STRING_FINDER_HPP