Chris@16: // Boost string_algo library finder.hpp header file ---------------------------// Chris@16: Chris@16: // Copyright Pavol Droba 2002-2006. Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org/ for updates, documentation, and revision history. Chris@16: Chris@16: #ifndef BOOST_STRING_FINDER_HPP Chris@16: #define BOOST_STRING_FINDER_HPP Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: /*! \file Chris@16: Defines Finder generators. Finder object is a functor which is able to Chris@16: find a substring matching a specific criteria in the input. Chris@16: Finders are used as a pluggable components for replace, find Chris@16: and split facilities. This header contains generator functions Chris@16: for finders provided in this library. Chris@16: */ Chris@16: Chris@16: namespace boost { Chris@16: namespace algorithm { Chris@16: Chris@16: // Finder generators ------------------------------------------// Chris@16: Chris@16: //! "First" finder Chris@16: /*! Chris@16: Construct the \c first_finder. The finder searches for the first Chris@16: occurrence of the string in a given input. Chris@16: The result is given as an \c iterator_range delimiting the match. Chris@16: Chris@16: \param Search A substring to be searched for. Chris@16: \param Comp An element comparison predicate Chris@16: \return An instance of the \c first_finder object Chris@16: */ Chris@16: template Chris@16: inline detail::first_finderF< Chris@16: BOOST_STRING_TYPENAME range_const_iterator::type, Chris@16: is_equal> Chris@16: first_finder( const RangeT& Search ) Chris@16: { Chris@16: return Chris@16: detail::first_finderF< Chris@16: BOOST_STRING_TYPENAME Chris@16: range_const_iterator::type, Chris@16: is_equal>( ::boost::as_literal(Search), is_equal() ) ; Chris@16: } Chris@16: Chris@16: //! "First" finder Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline detail::first_finderF< Chris@16: BOOST_STRING_TYPENAME range_const_iterator::type, Chris@16: PredicateT> Chris@16: first_finder( Chris@16: const RangeT& Search, PredicateT Comp ) Chris@16: { Chris@16: return Chris@16: detail::first_finderF< Chris@16: BOOST_STRING_TYPENAME Chris@16: range_const_iterator::type, Chris@16: PredicateT>( ::boost::as_literal(Search), Comp ); Chris@16: } Chris@16: Chris@16: //! "Last" finder Chris@16: /*! Chris@16: Construct the \c last_finder. The finder searches for the last Chris@16: occurrence of the string in a given input. Chris@16: The result is given as an \c iterator_range delimiting the match. Chris@16: Chris@16: \param Search A substring to be searched for. Chris@16: \param Comp An element comparison predicate Chris@16: \return An instance of the \c last_finder object Chris@16: */ Chris@16: template Chris@16: inline detail::last_finderF< Chris@16: BOOST_STRING_TYPENAME range_const_iterator::type, Chris@16: is_equal> Chris@16: last_finder( const RangeT& Search ) Chris@16: { Chris@16: return Chris@16: detail::last_finderF< Chris@16: BOOST_STRING_TYPENAME Chris@16: range_const_iterator::type, Chris@16: is_equal>( ::boost::as_literal(Search), is_equal() ); Chris@16: } Chris@16: //! "Last" finder Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline detail::last_finderF< Chris@16: BOOST_STRING_TYPENAME range_const_iterator::type, Chris@16: PredicateT> Chris@16: last_finder( const RangeT& Search, PredicateT Comp ) Chris@16: { Chris@16: return Chris@16: detail::last_finderF< Chris@16: BOOST_STRING_TYPENAME Chris@16: range_const_iterator::type, Chris@16: PredicateT>( ::boost::as_literal(Search), Comp ) ; Chris@16: } Chris@16: Chris@16: //! "Nth" finder Chris@16: /*! Chris@16: Construct the \c nth_finder. The finder searches for the n-th (zero-indexed) Chris@16: occurrence of the string in a given input. Chris@16: The result is given as an \c iterator_range delimiting the match. Chris@16: Chris@16: \param Search A substring to be searched for. Chris@16: \param Nth An index of the match to be find Chris@16: \param Comp An element comparison predicate Chris@16: \return An instance of the \c nth_finder object Chris@16: */ Chris@16: template Chris@16: inline detail::nth_finderF< Chris@16: BOOST_STRING_TYPENAME range_const_iterator::type, Chris@16: is_equal> Chris@16: nth_finder( Chris@16: const RangeT& Search, Chris@16: int Nth) Chris@16: { Chris@16: return Chris@16: detail::nth_finderF< Chris@16: BOOST_STRING_TYPENAME Chris@16: range_const_iterator::type, Chris@16: is_equal>( ::boost::as_literal(Search), Nth, is_equal() ) ; Chris@16: } Chris@16: //! "Nth" finder Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline detail::nth_finderF< Chris@16: BOOST_STRING_TYPENAME range_const_iterator::type, Chris@16: PredicateT> Chris@16: nth_finder( Chris@16: const RangeT& Search, Chris@16: int Nth, Chris@16: PredicateT Comp ) Chris@16: { Chris@16: return Chris@16: detail::nth_finderF< Chris@16: BOOST_STRING_TYPENAME Chris@16: range_const_iterator::type, Chris@16: PredicateT>( ::boost::as_literal(Search), Nth, Comp ); Chris@16: } Chris@16: Chris@16: //! "Head" finder Chris@16: /*! Chris@16: Construct the \c head_finder. The finder returns a head of a given Chris@16: input. The head is a prefix of a string up to n elements in Chris@16: size. If an input has less then n elements, whole input is Chris@16: considered a head. Chris@16: The result is given as an \c iterator_range delimiting the match. Chris@16: Chris@16: \param N The size of the head Chris@16: \return An instance of the \c head_finder object Chris@16: */ Chris@16: inline detail::head_finderF Chris@16: head_finder( int N ) Chris@16: { Chris@16: return detail::head_finderF(N); Chris@16: } Chris@16: Chris@16: //! "Tail" finder Chris@16: /*! Chris@16: Construct the \c tail_finder. The finder returns a tail of a given Chris@16: input. The tail is a suffix of a string up to n elements in Chris@16: size. If an input has less then n elements, whole input is Chris@16: considered a head. Chris@16: The result is given as an \c iterator_range delimiting the match. Chris@16: Chris@16: \param N The size of the head Chris@16: \return An instance of the \c tail_finder object Chris@16: */ Chris@16: inline detail::tail_finderF Chris@16: tail_finder( int N ) Chris@16: { Chris@16: return detail::tail_finderF(N); Chris@16: } Chris@16: Chris@16: //! "Token" finder Chris@16: /*! Chris@16: Construct the \c token_finder. The finder searches for a token Chris@16: specified by a predicate. It is similar to std::find_if Chris@16: algorithm, with an exception that it return a range of Chris@16: instead of a single iterator. Chris@16: Chris@16: If "compress token mode" is enabled, adjacent matching tokens are Chris@16: concatenated into one match. Thus the finder can be used to Chris@16: search for continuous segments of characters satisfying the Chris@16: given predicate. Chris@16: Chris@16: The result is given as an \c iterator_range delimiting the match. Chris@16: Chris@16: \param Pred An element selection predicate Chris@16: \param eCompress Compress flag Chris@16: \return An instance of the \c token_finder object Chris@16: */ Chris@16: template< typename PredicateT > Chris@16: inline detail::token_finderF Chris@16: token_finder( Chris@16: PredicateT Pred, Chris@16: token_compress_mode_type eCompress=token_compress_off ) Chris@16: { Chris@16: return detail::token_finderF( Pred, eCompress ); Chris@16: } Chris@16: Chris@16: //! "Range" finder Chris@16: /*! Chris@16: Construct the \c range_finder. The finder does not perform Chris@16: any operation. It simply returns the given range for Chris@16: any input. Chris@16: Chris@16: \param Begin Beginning of the range Chris@16: \param End End of the range Chris@16: \param Range The range. Chris@16: \return An instance of the \c range_finger object Chris@16: */ Chris@16: template< typename ForwardIteratorT > Chris@16: inline detail::range_finderF Chris@16: range_finder( Chris@16: ForwardIteratorT Begin, Chris@16: ForwardIteratorT End ) Chris@16: { Chris@16: return detail::range_finderF( Begin, End ); Chris@16: } Chris@16: Chris@16: //! "Range" finder Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template< typename ForwardIteratorT > Chris@16: inline detail::range_finderF Chris@16: range_finder( iterator_range Range ) Chris@16: { Chris@16: return detail::range_finderF( Range ); Chris@16: } Chris@16: Chris@16: } // namespace algorithm Chris@16: Chris@16: // pull the names to the boost namespace Chris@16: using algorithm::first_finder; Chris@16: using algorithm::last_finder; Chris@16: using algorithm::nth_finder; Chris@16: using algorithm::head_finder; Chris@16: using algorithm::tail_finder; Chris@16: using algorithm::token_finder; Chris@16: using algorithm::range_finder; Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: Chris@16: #endif // BOOST_STRING_FINDER_HPP