[857] | 1 | // Boost string_algo library finder.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_FINDER_HPP
|
---|
| 11 | #define BOOST_STRING_FINDER_HPP
|
---|
| 12 |
|
---|
| 13 | #include <boost/algorithm/string/config.hpp>
|
---|
| 14 |
|
---|
| 15 | #include <boost/range/iterator_range.hpp>
|
---|
| 16 | #include <boost/range/begin.hpp>
|
---|
| 17 | #include <boost/range/end.hpp>
|
---|
| 18 | #include <boost/range/iterator.hpp>
|
---|
| 19 | #include <boost/range/const_iterator.hpp>
|
---|
| 20 |
|
---|
| 21 | #include <boost/algorithm/string/constants.hpp>
|
---|
| 22 | #include <boost/algorithm/string/detail/finder.hpp>
|
---|
| 23 | #include <boost/algorithm/string/compare.hpp>
|
---|
| 24 |
|
---|
| 25 | /*! \file
|
---|
| 26 | Defines Finder generators. Finder object is a functor which is able to
|
---|
| 27 | find a substring matching a specific criteria in the input.
|
---|
| 28 | Finders are used as a pluggable components for replace, find
|
---|
| 29 | and split facilities. This header contains generator functions
|
---|
| 30 | for finders provided in this library.
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | namespace boost {
|
---|
| 34 | namespace algorithm {
|
---|
| 35 |
|
---|
| 36 | // Finder generators ------------------------------------------//
|
---|
| 37 |
|
---|
| 38 | //! "First" finder
|
---|
| 39 | /*!
|
---|
| 40 | Construct the \c first_finder. The finder searches for the first
|
---|
| 41 | occurrence of the string in a given input.
|
---|
| 42 | The result is given as an \c iterator_range delimiting the match.
|
---|
| 43 |
|
---|
| 44 | \param Search A substring to be searched for.
|
---|
| 45 | \param Comp An element comparison predicate
|
---|
| 46 | \return An instance of the \c first_finder object
|
---|
| 47 | */
|
---|
| 48 | template<typename ContainerT>
|
---|
| 49 | inline detail::first_finderF<
|
---|
| 50 | BOOST_STRING_TYPENAME range_const_iterator<ContainerT>::type,
|
---|
| 51 | is_equal>
|
---|
| 52 | first_finder( const ContainerT& Search )
|
---|
| 53 | {
|
---|
| 54 | return
|
---|
| 55 | detail::first_finderF<
|
---|
| 56 | BOOST_STRING_TYPENAME
|
---|
| 57 | range_const_iterator<ContainerT>::type,
|
---|
| 58 | is_equal>( Search, is_equal() ) ;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | //! "First" finder
|
---|
| 62 | /*!
|
---|
| 63 | \overload
|
---|
| 64 | */
|
---|
| 65 | template<typename ContainerT,typename PredicateT>
|
---|
| 66 | inline detail::first_finderF<
|
---|
| 67 | BOOST_STRING_TYPENAME range_const_iterator<ContainerT>::type,
|
---|
| 68 | PredicateT>
|
---|
| 69 | first_finder(
|
---|
| 70 | const ContainerT& Search, PredicateT Comp )
|
---|
| 71 | {
|
---|
| 72 | return
|
---|
| 73 | detail::first_finderF<
|
---|
| 74 | BOOST_STRING_TYPENAME
|
---|
| 75 | range_const_iterator<ContainerT>::type,
|
---|
| 76 | PredicateT>( Search, Comp );
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | //! "Last" finder
|
---|
| 80 | /*!
|
---|
| 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.
|
---|
| 84 |
|
---|
| 85 | \param Search A substring to be searched for.
|
---|
| 86 | \param Comp An element comparison predicate
|
---|
| 87 | \return An instance of the \c last_finder object
|
---|
| 88 | */
|
---|
| 89 | template<typename ContainerT>
|
---|
| 90 | inline detail::last_finderF<
|
---|
| 91 | BOOST_STRING_TYPENAME range_const_iterator<ContainerT>::type,
|
---|
| 92 | is_equal>
|
---|
| 93 | last_finder( const ContainerT& Search )
|
---|
| 94 | {
|
---|
| 95 | return
|
---|
| 96 | detail::last_finderF<
|
---|
| 97 | BOOST_STRING_TYPENAME
|
---|
| 98 | range_const_iterator<ContainerT>::type,
|
---|
| 99 | is_equal>( Search, is_equal() );
|
---|
| 100 | }
|
---|
| 101 | //! "Last" finder
|
---|
| 102 | /*!
|
---|
| 103 | \overload
|
---|
| 104 | */
|
---|
| 105 | template<typename ContainerT, typename PredicateT>
|
---|
| 106 | inline detail::last_finderF<
|
---|
| 107 | BOOST_STRING_TYPENAME range_const_iterator<ContainerT>::type,
|
---|
| 108 | PredicateT>
|
---|
| 109 | last_finder( const ContainerT& Search, PredicateT Comp )
|
---|
| 110 | {
|
---|
| 111 | return
|
---|
| 112 | detail::last_finderF<
|
---|
| 113 | BOOST_STRING_TYPENAME
|
---|
| 114 | range_const_iterator<ContainerT>::type,
|
---|
| 115 | PredicateT>( Search, Comp ) ;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | //! "Nth" finder
|
---|
| 119 | /*!
|
---|
| 120 | Construct the \c nth_finder. The finder searches for the n-th (zero-indexed)
|
---|
| 121 | occurrence of the string in a given input.
|
---|
| 122 | The result is given as an \c iterator_range delimiting the match.
|
---|
| 123 |
|
---|
| 124 | \param Search A substring to be searched for.
|
---|
| 125 | \param Nth An index of the match to be find
|
---|
| 126 | \param Comp An element comparison predicate
|
---|
| 127 | \return An instance of the \c nth_finder object
|
---|
| 128 | */
|
---|
| 129 | template<typename ContainerT>
|
---|
| 130 | inline detail::nth_finderF<
|
---|
| 131 | BOOST_STRING_TYPENAME range_const_iterator<ContainerT>::type,
|
---|
| 132 | is_equal>
|
---|
| 133 | nth_finder(
|
---|
| 134 | const ContainerT& Search,
|
---|
| 135 | unsigned int Nth)
|
---|
| 136 | {
|
---|
| 137 | return
|
---|
| 138 | detail::nth_finderF<
|
---|
| 139 | BOOST_STRING_TYPENAME
|
---|
| 140 | range_const_iterator<ContainerT>::type,
|
---|
| 141 | is_equal>( Search, Nth, is_equal() ) ;
|
---|
| 142 | }
|
---|
| 143 | //! "Nth" finder
|
---|
| 144 | /*!
|
---|
| 145 | \overload
|
---|
| 146 | */
|
---|
| 147 | template<typename ContainerT, typename PredicateT>
|
---|
| 148 | inline detail::nth_finderF<
|
---|
| 149 | BOOST_STRING_TYPENAME range_const_iterator<ContainerT>::type,
|
---|
| 150 | PredicateT>
|
---|
| 151 | nth_finder(
|
---|
| 152 | const ContainerT& Search,
|
---|
| 153 | unsigned int Nth,
|
---|
| 154 | PredicateT Comp )
|
---|
| 155 | {
|
---|
| 156 | return
|
---|
| 157 | detail::nth_finderF<
|
---|
| 158 | BOOST_STRING_TYPENAME
|
---|
| 159 | range_const_iterator<ContainerT>::type,
|
---|
| 160 | PredicateT>( Search, Nth, Comp );
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | //! "Head" finder
|
---|
| 164 | /*!
|
---|
| 165 | Construct the \c head_finder. The finder returns a head of a given
|
---|
| 166 | input. The head is a prefix of a string up to n elements in
|
---|
| 167 | size. If an input has less then n elements, whole input is
|
---|
| 168 | considered a head.
|
---|
| 169 | The result is given as an \c iterator_range delimiting the match.
|
---|
| 170 |
|
---|
| 171 | \param N The size of the head
|
---|
| 172 | \return An instance of the \c head_finder object
|
---|
| 173 | */
|
---|
| 174 | inline detail::head_finderF
|
---|
| 175 | head_finder( unsigned int N )
|
---|
| 176 | {
|
---|
| 177 | return detail::head_finderF(N);
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | //! "Tail" finder
|
---|
| 181 | /*!
|
---|
| 182 | Construct the \c tail_finder. The finder returns a tail of a given
|
---|
| 183 | input. The tail is a suffix of a string up to n elements in
|
---|
| 184 | size. If an input has less then n elements, whole input is
|
---|
| 185 | considered a head.
|
---|
| 186 | The result is given as an \c iterator_range delimiting the match.
|
---|
| 187 |
|
---|
| 188 | \param N The size of the head
|
---|
| 189 | \return An instance of the \c tail_finder object
|
---|
| 190 | */
|
---|
| 191 | inline detail::tail_finderF
|
---|
| 192 | tail_finder( unsigned int N )
|
---|
| 193 | {
|
---|
| 194 | return detail::tail_finderF(N);
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | //! "Token" finder
|
---|
| 198 | /*!
|
---|
| 199 | Construct the \c token_finder. The finder searches for a token
|
---|
| 200 | specified by a predicate. It is similar to std::find_if
|
---|
| 201 | algorithm, with an exception that it return a range of
|
---|
| 202 | instead of a single iterator.
|
---|
| 203 |
|
---|
| 204 | If "compress token mode" is enabled, adjacent matching tokens are
|
---|
| 205 | concatenated into one match. Thus the finder can be used to
|
---|
| 206 | search for continuous segments of characters satisfying the
|
---|
| 207 | given predicate.
|
---|
| 208 |
|
---|
| 209 | The result is given as an \c iterator_range delimiting the match.
|
---|
| 210 |
|
---|
| 211 | \param Pred An element selection predicate
|
---|
| 212 | \param eCompress Compress flag
|
---|
| 213 | \return An instance of the \c token_finder object
|
---|
| 214 | */
|
---|
| 215 | template< typename PredicateT >
|
---|
| 216 | inline detail::token_finderF<PredicateT>
|
---|
| 217 | token_finder(
|
---|
| 218 | PredicateT Pred,
|
---|
| 219 | token_compress_mode_type eCompress=token_compress_off )
|
---|
| 220 | {
|
---|
| 221 | return detail::token_finderF<PredicateT>( Pred, eCompress );
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | //! "Range" finder
|
---|
| 225 | /*!
|
---|
| 226 | Construct the \c range_finder. The finder does not perform
|
---|
| 227 | any operation. It simply returns the given range for
|
---|
| 228 | any input.
|
---|
| 229 |
|
---|
| 230 | \param Begin Beginning of the range
|
---|
| 231 | \param End End of the range
|
---|
| 232 | \param Range The range.
|
---|
| 233 | \return An instance of the \c range_finger object
|
---|
| 234 | */
|
---|
| 235 | template< typename ForwardIteratorT >
|
---|
| 236 | inline detail::range_finderF<ForwardIteratorT>
|
---|
| 237 | range_finder(
|
---|
| 238 | ForwardIteratorT Begin,
|
---|
| 239 | ForwardIteratorT End )
|
---|
| 240 | {
|
---|
| 241 | return detail::range_finderF<ForwardIteratorT>( Begin, End );
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | //! "Range" finder
|
---|
| 245 | /*!
|
---|
| 246 | \overload
|
---|
| 247 | */
|
---|
| 248 | template< typename ForwardIteratorT >
|
---|
| 249 | inline detail::range_finderF<ForwardIteratorT>
|
---|
| 250 | range_finder( iterator_range<ForwardIteratorT> Range )
|
---|
| 251 | {
|
---|
| 252 | return detail::range_finderF<ForwardIteratorT>( Range );
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | } // namespace algorithm
|
---|
| 256 |
|
---|
| 257 | // pull the names to the boost namespace
|
---|
| 258 | using algorithm::first_finder;
|
---|
| 259 | using algorithm::last_finder;
|
---|
| 260 | using algorithm::nth_finder;
|
---|
| 261 | using algorithm::head_finder;
|
---|
| 262 | using algorithm::tail_finder;
|
---|
| 263 | using algorithm::token_finder;
|
---|
| 264 | using algorithm::range_finder;
|
---|
| 265 |
|
---|
| 266 | } // namespace boost
|
---|
| 267 |
|
---|
| 268 |
|
---|
| 269 | #endif // BOOST_STRING_FINDER_HPP
|
---|