Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-16 09:04:48

0001 //  Boost string_algo library iter_find.hpp header file  ---------------------------//
0002 
0003 //  Copyright Pavol Droba 2002-2003.
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 //    (See accompanying file LICENSE_1_0.txt or copy at
0007 //          http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 //  See http://www.boost.org/ for updates, documentation, and revision history.
0010 
0011 #ifndef BOOST_STRING_ITER_FIND_HPP
0012 #define BOOST_STRING_ITER_FIND_HPP
0013 
0014 #include <boost/algorithm/string/config.hpp>
0015 #include <algorithm>
0016 #include <iterator>
0017 #include <boost/iterator/transform_iterator.hpp>
0018 
0019 #include <boost/range/iterator_range_core.hpp>
0020 #include <boost/range/begin.hpp>
0021 #include <boost/range/end.hpp>
0022 #include <boost/range/iterator.hpp>
0023 #include <boost/range/value_type.hpp>
0024 #include <boost/range/as_literal.hpp>
0025 
0026 #include <boost/algorithm/string/concept.hpp>
0027 #include <boost/algorithm/string/find_iterator.hpp>
0028 #include <boost/algorithm/string/detail/util.hpp>
0029 
0030 /*! \file
0031     Defines generic split algorithms. Split algorithms can be 
0032     used to divide a sequence into several part according 
0033     to a given criteria. Result is given as a 'container 
0034     of containers' where elements are copies or references 
0035     to extracted parts.
0036 
0037     There are two algorithms provided. One iterates over matching
0038     substrings, the other one over the gaps between these matches.
0039 */
0040 
0041 namespace boost {
0042     namespace algorithm {
0043 
0044 //  iterate find ---------------------------------------------------//
0045 
0046         //! Iter find algorithm
0047         /*!
0048             This algorithm executes a given finder in iteration on the input,
0049             until the end of input is reached, or no match is found.
0050             Iteration is done using built-in find_iterator, so the real 
0051             searching is performed only when needed.
0052             In each iteration new match is found and added to the result.
0053 
0054             \param Result A 'container container' to contain the result of search.
0055                 Both outer and inner container must have constructor taking a pair
0056                 of iterators as an argument.
0057                 Typical type of the result is 
0058                     \c std::vector<boost::iterator_range<iterator>>
0059                 (each element of such a vector will container a range delimiting 
0060                 a match).
0061             \param Input A container which will be searched.
0062             \param Finder A Finder object used for searching
0063             \return A reference to the result
0064 
0065             \note Prior content of the result will be overwritten.
0066         */
0067         template< 
0068             typename SequenceSequenceT,
0069             typename RangeT,
0070             typename FinderT >
0071         inline SequenceSequenceT&
0072         iter_find(
0073             SequenceSequenceT& Result,
0074 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0075             RangeT&& Input,
0076 #else
0077             RangeT& Input,
0078 #endif
0079             FinderT Finder )
0080         {
0081             BOOST_CONCEPT_ASSERT((
0082                 FinderConcept<
0083                     FinderT,
0084                     BOOST_STRING_TYPENAME range_iterator<RangeT>::type>
0085                 ));
0086 
0087             iterator_range<BOOST_STRING_TYPENAME range_iterator<RangeT>::type> lit_input(::boost::as_literal(Input));
0088 
0089             typedef BOOST_STRING_TYPENAME 
0090                 range_iterator<RangeT>::type input_iterator_type;
0091             typedef find_iterator<input_iterator_type> find_iterator_type;
0092             typedef detail::copy_iterator_rangeF<
0093                 BOOST_STRING_TYPENAME 
0094                     range_value<SequenceSequenceT>::type,
0095                 input_iterator_type> copy_range_type;
0096             
0097             input_iterator_type InputEnd=::boost::end(lit_input);
0098 
0099             typedef transform_iterator<copy_range_type, find_iterator_type>
0100                 transform_iter_type;
0101     
0102             transform_iter_type itBegin=
0103                 ::boost::make_transform_iterator( 
0104                     find_iterator_type( ::boost::begin(lit_input), InputEnd, Finder ),
0105                     copy_range_type());
0106             
0107             transform_iter_type itEnd=
0108                 ::boost::make_transform_iterator( 
0109                     find_iterator_type(),
0110                     copy_range_type());
0111 
0112             SequenceSequenceT Tmp(itBegin, itEnd);
0113                         
0114             Result.swap(Tmp);
0115             return Result;
0116         }
0117 
0118 //  iterate split ---------------------------------------------------//
0119 
0120         //! Split find algorithm
0121         /*!
0122             This algorithm executes a given finder in iteration on the input,
0123             until the end of input is reached, or no match is found.
0124             Iteration is done using built-in find_iterator, so the real 
0125             searching is performed only when needed.
0126             Each match is used as a separator of segments. These segments are then
0127             returned in the result.
0128 
0129             \param Result A 'container container' to contain the result of search.
0130                 Both outer and inner container must have constructor taking a pair
0131                 of iterators as an argument.
0132                 Typical type of the result is 
0133                     \c std::vector<boost::iterator_range<iterator>>
0134                 (each element of such a vector will container a range delimiting 
0135                 a match).
0136             \param Input A container which will be searched.
0137             \param Finder A finder object used for searching
0138             \return A reference to the result
0139 
0140             \note Prior content of the result will be overwritten.
0141         */
0142         template< 
0143             typename SequenceSequenceT,
0144             typename RangeT,
0145             typename FinderT >
0146         inline SequenceSequenceT&
0147         iter_split(
0148             SequenceSequenceT& Result,
0149 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0150             RangeT&& Input,
0151 #else
0152             RangeT& Input,
0153 #endif
0154             FinderT Finder )
0155         {
0156             BOOST_CONCEPT_ASSERT((
0157                 FinderConcept<FinderT,
0158                 BOOST_STRING_TYPENAME range_iterator<RangeT>::type>
0159                 ));
0160 
0161             iterator_range<BOOST_STRING_TYPENAME range_iterator<RangeT>::type> lit_input(::boost::as_literal(Input));
0162 
0163             typedef BOOST_STRING_TYPENAME 
0164                 range_iterator<RangeT>::type input_iterator_type;
0165             typedef split_iterator<input_iterator_type> find_iterator_type;
0166             typedef detail::copy_iterator_rangeF<
0167                 BOOST_STRING_TYPENAME 
0168                     range_value<SequenceSequenceT>::type,
0169                 input_iterator_type> copy_range_type;
0170             
0171             input_iterator_type InputEnd=::boost::end(lit_input);
0172 
0173             typedef transform_iterator<copy_range_type, find_iterator_type>
0174                 transform_iter_type;
0175     
0176             transform_iter_type itBegin=
0177                 ::boost::make_transform_iterator( 
0178                     find_iterator_type( ::boost::begin(lit_input), InputEnd, Finder ),
0179                     copy_range_type() );
0180 
0181             transform_iter_type itEnd=
0182                 ::boost::make_transform_iterator( 
0183                     find_iterator_type(),
0184                     copy_range_type() );
0185             
0186             SequenceSequenceT Tmp(itBegin, itEnd);
0187 
0188             Result.swap(Tmp);
0189             return Result;
0190         }
0191 
0192     } // namespace algorithm
0193 
0194     // pull names to the boost namespace
0195     using algorithm::iter_find;
0196     using algorithm::iter_split;
0197 
0198 } // namespace boost
0199 
0200 
0201 #endif  // BOOST_STRING_ITER_FIND_HPP