source: NonGTP/Boost/boost/algorithm/string/iter_find.hpp @ 857

Revision 857, 7.0 KB checked in by igarcia, 19 years ago (diff)
Line 
1//  Boost string_algo library iter_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_ITER_FIND_HPP
11#define BOOST_STRING_ITER_FIND_HPP
12
13#include <boost/algorithm/string/config.hpp>
14#include <algorithm>
15#include <iterator>
16#include <boost/iterator/transform_iterator.hpp>
17
18#include <boost/range/iterator_range.hpp>
19#include <boost/range/begin.hpp>
20#include <boost/range/end.hpp>
21#include <boost/range/result_iterator.hpp>
22#include <boost/range/value_type.hpp>
23
24#include <boost/algorithm/string/concept.hpp>
25#include <boost/algorithm/string/find_iterator.hpp>
26#include <boost/algorithm/string/detail/util.hpp>
27
28/*! \file
29    Defines generic split algorithms. Split algorithms can be
30    used to divide a sequence into several part according
31    to a given criteria. Result is given as a 'container
32    of containers' where elements are copies or references
33    to extracted parts.
34
35    There are two algorithms provided. One iterates over matching
36    substrings, the other one over the gaps between these matches.
37*/
38
39namespace boost {
40    namespace algorithm {
41
42//  iterate find ---------------------------------------------------//
43
44        //! Iter find algorithm
45        /*!
46            This algorithm executes a given finder in iteration on the input,
47            until the end of input is reached, or no match is found.
48            Iteration is done using built-in find_iterator, so the real
49            searching is performed only when needed.
50            In each iteration new match is found and added to the result.
51
52            \param Result A 'container container' to contain the result of search.
53                Both outer and inner container must have constructor taking a pair
54                of iterators as an argument.
55                Typical type of the result is
56                    \c std::vector<boost::iterator_range<iterator>>
57                (each element of such a vector will container a range delimiting
58                a match).
59            \param Input A container which will be searched.
60            \param Finder A Finder object used for searching
61            \return A reference the result
62
63            \note Prior content of the result will be overwritten.
64        */
65        template<
66            typename SequenceSequenceT,
67            typename RangeT,
68            typename FinderT >
69        inline SequenceSequenceT&
70        iter_find(
71            SequenceSequenceT& Result,
72            RangeT& Input,
73            FinderT Finder )
74        {
75            function_requires<
76                FinderConcept<FinderT,
77                BOOST_STRING_TYPENAME range_result_iterator<RangeT>::type> >();
78
79            typedef BOOST_STRING_TYPENAME
80                range_result_iterator<RangeT>::type input_iterator_type;
81            typedef find_iterator<input_iterator_type> find_iterator_type;
82            typedef detail::copy_iterator_rangeF<
83                BOOST_STRING_TYPENAME
84                    range_value<SequenceSequenceT>::type,
85                input_iterator_type> copy_range_type;
86           
87            input_iterator_type InputEnd=end(Input);
88
89            typedef transform_iterator<copy_range_type, find_iterator_type>
90                transform_iter_type;
91   
92            transform_iter_type itBegin=
93                make_transform_iterator(
94                    find_iterator_type( begin(Input), InputEnd, Finder ),
95                    copy_range_type());
96           
97            transform_iter_type itEnd=
98                make_transform_iterator(
99                    find_iterator_type(),
100                    copy_range_type());
101
102            SequenceSequenceT Tmp(itBegin, itEnd);
103                       
104            Result.swap(Tmp);
105            return Result;
106        }
107
108//  iterate split ---------------------------------------------------//
109
110        //! Split find algorithm
111        /*!
112            This algorithm executes a given finder in iteration on the input,
113            until the end of input is reached, or no match is found.
114            Iteration is done using built-in find_iterator, so the real
115            searching is performed only when needed.
116            Each match is used as a separator of segments. These segments are then
117            returned in the result.
118
119            \param Result A 'container container' to container the result of search.
120                Both outer and inner container must have constructor taking a pair
121                of iterators as an argument.
122                Typical type of the result is
123                    \c std::vector<boost::iterator_range<iterator>>
124                (each element of such a vector will container a range delimiting
125                a match).
126            \param Input A container which will be searched.
127            \param Finder A finder object used for searching
128            \return A reference the result
129
130            \note Prior content of the result will be overwritten.
131        */
132        template<
133            typename SequenceSequenceT,
134            typename RangeT,
135            typename FinderT >
136        inline SequenceSequenceT&
137        iter_split(
138            SequenceSequenceT& Result,
139            RangeT& Input,
140            FinderT Finder )
141        {
142            function_requires<
143                FinderConcept<FinderT,
144                BOOST_STRING_TYPENAME range_result_iterator<RangeT>::type> >();
145
146            typedef BOOST_STRING_TYPENAME
147                range_result_iterator<RangeT>::type input_iterator_type;
148            typedef split_iterator<input_iterator_type> find_iterator_type;
149            typedef detail::copy_iterator_rangeF<
150                BOOST_STRING_TYPENAME
151                    range_value<SequenceSequenceT>::type,
152                input_iterator_type> copy_range_type;
153           
154            input_iterator_type InputEnd=end(Input);
155
156            typedef transform_iterator<copy_range_type, find_iterator_type>
157                transform_iter_type;
158   
159            transform_iter_type itBegin=
160                make_transform_iterator(
161                    find_iterator_type( begin(Input), InputEnd, Finder ),
162                    copy_range_type() );
163
164            transform_iter_type itEnd=
165                make_transform_iterator(
166                    find_iterator_type(),
167                    copy_range_type() );
168           
169            SequenceSequenceT Tmp(itBegin, itEnd);
170
171            Result.swap(Tmp);
172            return Result;
173        }
174
175    } // namespace algorithm
176
177    // pull names to the boost namespace
178    using algorithm::iter_find;
179    using algorithm::iter_split;
180
181} // namespace boost
182
183
184#endif  // BOOST_STRING_ITER_FIND_HPP
Note: See TracBrowser for help on using the repository browser.