Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / algorithm / string / find.hpp @ 2486

History | View | Annotate | Download (12.8 kB)

1 2486 sjacqu01
//  Boost string_algo library find.hpp header file  ---------------------------//
2 2486 sjacqu01
3 2486 sjacqu01
//  Copyright Pavol Droba 2002-2003.
4 2486 sjacqu01
//
5 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0.
6 2486 sjacqu01
//    (See accompanying file LICENSE_1_0.txt or copy at
7 2486 sjacqu01
//          http://www.boost.org/LICENSE_1_0.txt)
8 2486 sjacqu01
9 2486 sjacqu01
//  See http://www.boost.org/ for updates, documentation, and revision history.
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_STRING_FIND_HPP
12 2486 sjacqu01
#define BOOST_STRING_FIND_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#include <boost/algorithm/string/config.hpp>
15 2486 sjacqu01
16 2486 sjacqu01
#include <boost/range/iterator_range_core.hpp>
17 2486 sjacqu01
#include <boost/range/begin.hpp>
18 2486 sjacqu01
#include <boost/range/end.hpp>
19 2486 sjacqu01
#include <boost/range/iterator.hpp>
20 2486 sjacqu01
#include <boost/range/as_literal.hpp>
21 2486 sjacqu01
22 2486 sjacqu01
#include <boost/algorithm/string/finder.hpp>
23 2486 sjacqu01
#include <boost/algorithm/string/compare.hpp>
24 2486 sjacqu01
#include <boost/algorithm/string/constants.hpp>
25 2486 sjacqu01
26 2486 sjacqu01
/*! \file
27 2486 sjacqu01
    Defines a set of find algorithms. The algorithms are searching
28 2486 sjacqu01
    for a substring of the input. The result is given as an \c iterator_range
29 2486 sjacqu01
    delimiting the substring.
30 2486 sjacqu01
*/
31 2486 sjacqu01
32 2486 sjacqu01
namespace boost {
33 2486 sjacqu01
    namespace algorithm {
34 2486 sjacqu01
35 2486 sjacqu01
//  Generic find -----------------------------------------------//
36 2486 sjacqu01
37 2486 sjacqu01
        //! Generic find algorithm
38 2486 sjacqu01
        /*!
39 2486 sjacqu01
            Search the input using the given finder.
40 2486 sjacqu01

41 2486 sjacqu01
            \param Input A string which will be searched.
42 2486 sjacqu01
            \param Finder Finder object used for searching.
43 2486 sjacqu01
            \return
44 2486 sjacqu01
                An \c iterator_range delimiting the match.
45 2486 sjacqu01
                Returned iterator is either \c RangeT::iterator or
46 2486 sjacqu01
                \c RangeT::const_iterator, depending on the constness of
47 2486 sjacqu01
                the input parameter.
48 2486 sjacqu01
        */
49 2486 sjacqu01
        template<typename RangeT, typename FinderT>
50 2486 sjacqu01
        inline iterator_range<
51 2486 sjacqu01
            BOOST_STRING_TYPENAME range_iterator<RangeT>::type>
52 2486 sjacqu01
        find(
53 2486 sjacqu01
            RangeT& Input,
54 2486 sjacqu01
            const FinderT& Finder)
55 2486 sjacqu01
        {
56 2486 sjacqu01
            iterator_range<BOOST_STRING_TYPENAME range_iterator<RangeT>::type> lit_input(::boost::as_literal(Input));
57 2486 sjacqu01
58 2486 sjacqu01
            return Finder(::boost::begin(lit_input),::boost::end(lit_input));
59 2486 sjacqu01
        }
60 2486 sjacqu01
61 2486 sjacqu01
//  find_first  -----------------------------------------------//
62 2486 sjacqu01
63 2486 sjacqu01
        //! Find first algorithm
64 2486 sjacqu01
        /*!
65 2486 sjacqu01
            Search for the first occurrence of the substring in the input.
66 2486 sjacqu01

67 2486 sjacqu01
            \param Input A string which will be searched.
68 2486 sjacqu01
            \param Search A substring to be searched for.
69 2486 sjacqu01
            \return
70 2486 sjacqu01
                An \c iterator_range delimiting the match.
71 2486 sjacqu01
                Returned iterator is either \c RangeT::iterator or
72 2486 sjacqu01
                \c RangeT::const_iterator, depending on the constness of
73 2486 sjacqu01
                the input parameter.
74 2486 sjacqu01

75 2486 sjacqu01
              \note This function provides the strong exception-safety guarantee
76 2486 sjacqu01
        */
77 2486 sjacqu01
        template<typename Range1T, typename Range2T>
78 2486 sjacqu01
        inline iterator_range<
79 2486 sjacqu01
            BOOST_STRING_TYPENAME range_iterator<Range1T>::type>
80 2486 sjacqu01
        find_first(
81 2486 sjacqu01
            Range1T& Input,
82 2486 sjacqu01
            const Range2T& Search)
83 2486 sjacqu01
        {
84 2486 sjacqu01
            return ::boost::algorithm::find(Input, ::boost::algorithm::first_finder(Search));
85 2486 sjacqu01
        }
86 2486 sjacqu01
87 2486 sjacqu01
        //! Find first algorithm ( case insensitive )
88 2486 sjacqu01
        /*!
89 2486 sjacqu01
            Search for the first occurrence of the substring in the input.
90 2486 sjacqu01
            Searching is case insensitive.
91 2486 sjacqu01

92 2486 sjacqu01
            \param Input A string which will be searched.
93 2486 sjacqu01
            \param Search A substring to be searched for.
94 2486 sjacqu01
            \param Loc A locale used for case insensitive comparison
95 2486 sjacqu01
            \return
96 2486 sjacqu01
                An \c iterator_range delimiting the match.
97 2486 sjacqu01
                Returned iterator is either \c Range1T::iterator or
98 2486 sjacqu01
                \c Range1T::const_iterator, depending on the constness of
99 2486 sjacqu01
                the input parameter.
100 2486 sjacqu01

101 2486 sjacqu01
            \note This function provides the strong exception-safety guarantee
102 2486 sjacqu01
        */
103 2486 sjacqu01
        template<typename Range1T, typename Range2T>
104 2486 sjacqu01
        inline iterator_range<
105 2486 sjacqu01
            BOOST_STRING_TYPENAME range_iterator<Range1T>::type>
106 2486 sjacqu01
        ifind_first(
107 2486 sjacqu01
            Range1T& Input,
108 2486 sjacqu01
            const Range2T& Search,
109 2486 sjacqu01
            const std::locale& Loc=std::locale())
110 2486 sjacqu01
        {
111 2486 sjacqu01
            return ::boost::algorithm::find(Input, ::boost::algorithm::first_finder(Search,is_iequal(Loc)));
112 2486 sjacqu01
        }
113 2486 sjacqu01
114 2486 sjacqu01
//  find_last  -----------------------------------------------//
115 2486 sjacqu01
116 2486 sjacqu01
        //! Find last algorithm
117 2486 sjacqu01
        /*!
118 2486 sjacqu01
            Search for the last occurrence of the substring in the input.
119 2486 sjacqu01

120 2486 sjacqu01
            \param Input A string which will be searched.
121 2486 sjacqu01
            \param Search A substring to be searched for.
122 2486 sjacqu01
            \return
123 2486 sjacqu01
                An \c iterator_range delimiting the match.
124 2486 sjacqu01
                Returned iterator is either \c Range1T::iterator or
125 2486 sjacqu01
                \c Range1T::const_iterator, depending on the constness of
126 2486 sjacqu01
                the input parameter.
127 2486 sjacqu01

128 2486 sjacqu01
            \note This function provides the strong exception-safety guarantee
129 2486 sjacqu01
        */
130 2486 sjacqu01
        template<typename Range1T, typename Range2T>
131 2486 sjacqu01
        inline iterator_range<
132 2486 sjacqu01
            BOOST_STRING_TYPENAME range_iterator<Range1T>::type>
133 2486 sjacqu01
        find_last(
134 2486 sjacqu01
            Range1T& Input,
135 2486 sjacqu01
            const Range2T& Search)
136 2486 sjacqu01
        {
137 2486 sjacqu01
            return ::boost::algorithm::find(Input, ::boost::algorithm::last_finder(Search));
138 2486 sjacqu01
        }
139 2486 sjacqu01
140 2486 sjacqu01
        //! Find last algorithm ( case insensitive )
141 2486 sjacqu01
        /*!
142 2486 sjacqu01
            Search for the last match a string in the input.
143 2486 sjacqu01
            Searching is case insensitive.
144 2486 sjacqu01

145 2486 sjacqu01
            \param Input A string which will be searched.
146 2486 sjacqu01
            \param Search A substring to be searched for.
147 2486 sjacqu01
            \param Loc A locale used for case insensitive comparison
148 2486 sjacqu01
            \return
149 2486 sjacqu01
                An \c iterator_range delimiting the match.
150 2486 sjacqu01
                Returned iterator is either \c Range1T::iterator or
151 2486 sjacqu01
                \c Range1T::const_iterator, depending on the constness of
152 2486 sjacqu01
                the input parameter.
153 2486 sjacqu01

154 2486 sjacqu01
            \note This function provides the strong exception-safety guarantee
155 2486 sjacqu01
        */
156 2486 sjacqu01
        template<typename Range1T, typename Range2T>
157 2486 sjacqu01
        inline iterator_range<
158 2486 sjacqu01
            BOOST_STRING_TYPENAME range_iterator<Range1T>::type>
159 2486 sjacqu01
        ifind_last(
160 2486 sjacqu01
            Range1T& Input,
161 2486 sjacqu01
            const Range2T& Search,
162 2486 sjacqu01
            const std::locale& Loc=std::locale())
163 2486 sjacqu01
        {
164 2486 sjacqu01
            return ::boost::algorithm::find(Input, ::boost::algorithm::last_finder(Search, is_iequal(Loc)));
165 2486 sjacqu01
        }
166 2486 sjacqu01
167 2486 sjacqu01
//  find_nth ----------------------------------------------------------------------//
168 2486 sjacqu01
169 2486 sjacqu01
        //! Find n-th algorithm
170 2486 sjacqu01
        /*!
171 2486 sjacqu01
            Search for the n-th (zero-indexed) occurrence of the substring in the
172 2486 sjacqu01
            input.
173 2486 sjacqu01

174 2486 sjacqu01
            \param Input A string which will be searched.
175 2486 sjacqu01
            \param Search A substring to be searched for.
176 2486 sjacqu01
            \param Nth An index (zero-indexed) of the match to be found.
177 2486 sjacqu01
                For negative N, the matches are counted from the end of string.
178 2486 sjacqu01
            \return
179 2486 sjacqu01
                An \c iterator_range delimiting the match.
180 2486 sjacqu01
                Returned iterator is either \c Range1T::iterator or
181 2486 sjacqu01
                \c Range1T::const_iterator, depending on the constness of
182 2486 sjacqu01
                the input parameter.
183 2486 sjacqu01
        */
184 2486 sjacqu01
        template<typename Range1T, typename Range2T>
185 2486 sjacqu01
        inline iterator_range<
186 2486 sjacqu01
            BOOST_STRING_TYPENAME range_iterator<Range1T>::type>
187 2486 sjacqu01
        find_nth(
188 2486 sjacqu01
            Range1T& Input,
189 2486 sjacqu01
            const Range2T& Search,
190 2486 sjacqu01
            int Nth)
191 2486 sjacqu01
        {
192 2486 sjacqu01
            return ::boost::algorithm::find(Input, ::boost::algorithm::nth_finder(Search,Nth));
193 2486 sjacqu01
        }
194 2486 sjacqu01
195 2486 sjacqu01
        //! Find n-th algorithm ( case insensitive ).
196 2486 sjacqu01
        /*!
197 2486 sjacqu01
            Search for the n-th (zero-indexed) occurrence of the substring in the
198 2486 sjacqu01
            input. Searching is case insensitive.
199 2486 sjacqu01

200 2486 sjacqu01
            \param Input A string which will be searched.
201 2486 sjacqu01
            \param Search A substring to be searched for.
202 2486 sjacqu01
            \param Nth An index (zero-indexed) of the match to be found.
203 2486 sjacqu01
                For negative N, the matches are counted from the end of string.
204 2486 sjacqu01
            \param Loc A locale used for case insensitive comparison
205 2486 sjacqu01
            \return
206 2486 sjacqu01
                An \c iterator_range delimiting the match.
207 2486 sjacqu01
                Returned iterator is either \c Range1T::iterator or
208 2486 sjacqu01
                \c Range1T::const_iterator, depending on the constness of
209 2486 sjacqu01
                the input parameter.
210 2486 sjacqu01

211 2486 sjacqu01

212 2486 sjacqu01
            \note This function provides the strong exception-safety guarantee
213 2486 sjacqu01
        */
214 2486 sjacqu01
        template<typename Range1T, typename Range2T>
215 2486 sjacqu01
        inline iterator_range<
216 2486 sjacqu01
            BOOST_STRING_TYPENAME range_iterator<Range1T>::type>
217 2486 sjacqu01
        ifind_nth(
218 2486 sjacqu01
            Range1T& Input,
219 2486 sjacqu01
            const Range2T& Search,
220 2486 sjacqu01
            int Nth,
221 2486 sjacqu01
            const std::locale& Loc=std::locale())
222 2486 sjacqu01
        {
223 2486 sjacqu01
            return ::boost::algorithm::find(Input, ::boost::algorithm::nth_finder(Search,Nth,is_iequal(Loc)));
224 2486 sjacqu01
        }
225 2486 sjacqu01
226 2486 sjacqu01
//  find_head ----------------------------------------------------------------------//
227 2486 sjacqu01
228 2486 sjacqu01
        //! Find head algorithm
229 2486 sjacqu01
        /*!
230 2486 sjacqu01
            Get the head of the input. Head is a prefix of the string of the
231 2486 sjacqu01
            given size. If the input is shorter then required, whole input is considered
232 2486 sjacqu01
            to be the head.
233 2486 sjacqu01

234 2486 sjacqu01
            \param Input An input string
235 2486 sjacqu01
            \param N Length of the head
236 2486 sjacqu01
                For N>=0, at most N characters are extracted.
237 2486 sjacqu01
                For N<0, at most size(Input)-|N| characters are extracted.
238 2486 sjacqu01
            \return
239 2486 sjacqu01
                An \c iterator_range delimiting the match.
240 2486 sjacqu01
                Returned iterator is either \c Range1T::iterator or
241 2486 sjacqu01
                \c Range1T::const_iterator, depending on the constness of
242 2486 sjacqu01
                the input parameter.
243 2486 sjacqu01

244 2486 sjacqu01
            \note This function provides the strong exception-safety guarantee
245 2486 sjacqu01
        */
246 2486 sjacqu01
        template<typename RangeT>
247 2486 sjacqu01
        inline iterator_range<
248 2486 sjacqu01
            BOOST_STRING_TYPENAME range_iterator<RangeT>::type>
249 2486 sjacqu01
        find_head(
250 2486 sjacqu01
            RangeT& Input,
251 2486 sjacqu01
            int N)
252 2486 sjacqu01
        {
253 2486 sjacqu01
            return ::boost::algorithm::find(Input, ::boost::algorithm::head_finder(N));
254 2486 sjacqu01
        }
255 2486 sjacqu01
256 2486 sjacqu01
//  find_tail ----------------------------------------------------------------------//
257 2486 sjacqu01
258 2486 sjacqu01
        //! Find tail algorithm
259 2486 sjacqu01
        /*!
260 2486 sjacqu01
            Get the tail of the input. Tail is a suffix of the string of the
261 2486 sjacqu01
            given size. If the input is shorter then required, whole input is considered
262 2486 sjacqu01
            to be the tail.
263 2486 sjacqu01

264 2486 sjacqu01
            \param Input An input string
265 2486 sjacqu01
            \param N Length of the tail.
266 2486 sjacqu01
                For N>=0, at most N characters are extracted.
267 2486 sjacqu01
                For N<0, at most size(Input)-|N| characters are extracted.
268 2486 sjacqu01
            \return
269 2486 sjacqu01
                An \c iterator_range delimiting the match.
270 2486 sjacqu01
                Returned iterator is either \c RangeT::iterator or
271 2486 sjacqu01
                \c RangeT::const_iterator, depending on the constness of
272 2486 sjacqu01
                the input parameter.
273 2486 sjacqu01

274 2486 sjacqu01

275 2486 sjacqu01
            \note This function provides the strong exception-safety guarantee
276 2486 sjacqu01
        */
277 2486 sjacqu01
        template<typename RangeT>
278 2486 sjacqu01
        inline iterator_range<
279 2486 sjacqu01
            BOOST_STRING_TYPENAME range_iterator<RangeT>::type>
280 2486 sjacqu01
        find_tail(
281 2486 sjacqu01
            RangeT& Input,
282 2486 sjacqu01
            int N)
283 2486 sjacqu01
        {
284 2486 sjacqu01
            return ::boost::algorithm::find(Input, ::boost::algorithm::tail_finder(N));
285 2486 sjacqu01
        }
286 2486 sjacqu01
287 2486 sjacqu01
//  find_token --------------------------------------------------------------------//
288 2486 sjacqu01
289 2486 sjacqu01
        //! Find token algorithm
290 2486 sjacqu01
        /*!
291 2486 sjacqu01
            Look for a given token in the string. Token is a character that matches the
292 2486 sjacqu01
            given predicate.
293 2486 sjacqu01
            If the "token compress mode" is enabled, adjacent tokens are considered to be one match.
294 2486 sjacqu01

295 2486 sjacqu01
            \param Input A input string.
296 2486 sjacqu01
            \param Pred A unary predicate to identify a token
297 2486 sjacqu01
            \param eCompress Enable/Disable compressing of adjacent tokens
298 2486 sjacqu01
            \return
299 2486 sjacqu01
                An \c iterator_range delimiting the match.
300 2486 sjacqu01
                Returned iterator is either \c RangeT::iterator or
301 2486 sjacqu01
                \c RangeT::const_iterator, depending on the constness of
302 2486 sjacqu01
                the input parameter.
303 2486 sjacqu01

304 2486 sjacqu01
            \note This function provides the strong exception-safety guarantee
305 2486 sjacqu01
        */
306 2486 sjacqu01
        template<typename RangeT, typename PredicateT>
307 2486 sjacqu01
        inline iterator_range<
308 2486 sjacqu01
            BOOST_STRING_TYPENAME range_iterator<RangeT>::type>
309 2486 sjacqu01
        find_token(
310 2486 sjacqu01
            RangeT& Input,
311 2486 sjacqu01
            PredicateT Pred,
312 2486 sjacqu01
            token_compress_mode_type eCompress=token_compress_off)
313 2486 sjacqu01
        {
314 2486 sjacqu01
            return ::boost::algorithm::find(Input, ::boost::algorithm::token_finder(Pred, eCompress));
315 2486 sjacqu01
        }
316 2486 sjacqu01
317 2486 sjacqu01
    } // namespace algorithm
318 2486 sjacqu01
319 2486 sjacqu01
    // pull names to the boost namespace
320 2486 sjacqu01
    using algorithm::find;
321 2486 sjacqu01
    using algorithm::find_first;
322 2486 sjacqu01
    using algorithm::ifind_first;
323 2486 sjacqu01
    using algorithm::find_last;
324 2486 sjacqu01
    using algorithm::ifind_last;
325 2486 sjacqu01
    using algorithm::find_nth;
326 2486 sjacqu01
    using algorithm::ifind_nth;
327 2486 sjacqu01
    using algorithm::find_head;
328 2486 sjacqu01
    using algorithm::find_tail;
329 2486 sjacqu01
    using algorithm::find_token;
330 2486 sjacqu01
331 2486 sjacqu01
} // namespace boost
332 2486 sjacqu01
333 2486 sjacqu01
334 2486 sjacqu01
#endif  // BOOST_STRING_FIND_HPP