Chris@16: // Boost string_algo library find.hpp header file ---------------------------// Chris@16: Chris@16: // Copyright Pavol Droba 2002-2003. 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_FIND_HPP Chris@16: #define BOOST_STRING_FIND_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 a set of find algorithms. The algorithms are searching Chris@16: for a substring of the input. The result is given as an \c iterator_range Chris@16: delimiting the substring. Chris@16: */ Chris@16: Chris@16: namespace boost { Chris@16: namespace algorithm { Chris@16: Chris@16: // Generic find -----------------------------------------------// Chris@16: Chris@16: //! Generic find algorithm Chris@16: /*! Chris@16: Search the input using the given finder. Chris@16: Chris@16: \param Input A string which will be searched. Chris@16: \param Finder Finder object used for searching. Chris@16: \return Chris@16: An \c iterator_range delimiting the match. Chris@16: Returned iterator is either \c RangeT::iterator or Chris@16: \c RangeT::const_iterator, depending on the constness of Chris@16: the input parameter. Chris@16: */ Chris@16: template Chris@16: inline iterator_range< Chris@16: BOOST_STRING_TYPENAME range_iterator::type> Chris@16: find( Chris@16: RangeT& Input, Chris@16: const FinderT& Finder) Chris@16: { Chris@16: iterator_range::type> lit_input(::boost::as_literal(Input)); Chris@16: Chris@16: return Finder(::boost::begin(lit_input),::boost::end(lit_input)); Chris@16: } Chris@16: Chris@16: // find_first -----------------------------------------------// Chris@16: Chris@16: //! Find first algorithm Chris@16: /*! Chris@16: Search for the first occurrence of the substring in the input. Chris@16: Chris@16: \param Input A string which will be searched. Chris@16: \param Search A substring to be searched for. Chris@16: \return Chris@16: An \c iterator_range delimiting the match. Chris@16: Returned iterator is either \c RangeT::iterator or Chris@16: \c RangeT::const_iterator, depending on the constness of Chris@16: the input parameter. Chris@16: Chris@16: \note This function provides the strong exception-safety guarantee Chris@16: */ Chris@16: template Chris@16: inline iterator_range< Chris@16: BOOST_STRING_TYPENAME range_iterator::type> Chris@16: find_first( Chris@16: Range1T& Input, Chris@16: const Range2T& Search) Chris@16: { Chris@16: return ::boost::algorithm::find(Input, ::boost::algorithm::first_finder(Search)); Chris@16: } Chris@16: Chris@16: //! Find first algorithm ( case insensitive ) Chris@16: /*! Chris@16: Search for the first occurrence of the substring in the input. Chris@16: Searching is case insensitive. Chris@16: Chris@16: \param Input A string which will be searched. Chris@16: \param Search A substring to be searched for. Chris@16: \param Loc A locale used for case insensitive comparison Chris@16: \return Chris@16: An \c iterator_range delimiting the match. Chris@16: Returned iterator is either \c Range1T::iterator or Chris@16: \c Range1T::const_iterator, depending on the constness of Chris@16: the input parameter. Chris@16: Chris@16: \note This function provides the strong exception-safety guarantee Chris@16: */ Chris@16: template Chris@16: inline iterator_range< Chris@16: BOOST_STRING_TYPENAME range_iterator::type> Chris@16: ifind_first( Chris@16: Range1T& Input, Chris@16: const Range2T& Search, Chris@16: const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return ::boost::algorithm::find(Input, ::boost::algorithm::first_finder(Search,is_iequal(Loc))); Chris@16: } Chris@16: Chris@16: // find_last -----------------------------------------------// Chris@16: Chris@16: //! Find last algorithm Chris@16: /*! Chris@16: Search for the last occurrence of the substring in the input. Chris@16: Chris@16: \param Input A string which will be searched. Chris@16: \param Search A substring to be searched for. Chris@16: \return Chris@16: An \c iterator_range delimiting the match. Chris@16: Returned iterator is either \c Range1T::iterator or Chris@16: \c Range1T::const_iterator, depending on the constness of Chris@16: the input parameter. Chris@16: Chris@16: \note This function provides the strong exception-safety guarantee Chris@16: */ Chris@16: template Chris@16: inline iterator_range< Chris@16: BOOST_STRING_TYPENAME range_iterator::type> Chris@16: find_last( Chris@16: Range1T& Input, Chris@16: const Range2T& Search) Chris@16: { Chris@16: return ::boost::algorithm::find(Input, ::boost::algorithm::last_finder(Search)); Chris@16: } Chris@16: Chris@16: //! Find last algorithm ( case insensitive ) Chris@16: /*! Chris@16: Search for the last match a string in the input. Chris@16: Searching is case insensitive. Chris@16: Chris@16: \param Input A string which will be searched. Chris@16: \param Search A substring to be searched for. Chris@16: \param Loc A locale used for case insensitive comparison Chris@16: \return Chris@16: An \c iterator_range delimiting the match. Chris@16: Returned iterator is either \c Range1T::iterator or Chris@16: \c Range1T::const_iterator, depending on the constness of Chris@16: the input parameter. Chris@16: Chris@16: \note This function provides the strong exception-safety guarantee Chris@16: */ Chris@16: template Chris@16: inline iterator_range< Chris@16: BOOST_STRING_TYPENAME range_iterator::type> Chris@16: ifind_last( Chris@16: Range1T& Input, Chris@16: const Range2T& Search, Chris@16: const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return ::boost::algorithm::find(Input, ::boost::algorithm::last_finder(Search, is_iequal(Loc))); Chris@16: } Chris@16: Chris@16: // find_nth ----------------------------------------------------------------------// Chris@16: Chris@16: //! Find n-th algorithm Chris@16: /*! Chris@16: Search for the n-th (zero-indexed) occurrence of the substring in the Chris@16: input. Chris@16: Chris@16: \param Input A string which will be searched. Chris@16: \param Search A substring to be searched for. Chris@16: \param Nth An index (zero-indexed) of the match to be found. Chris@16: For negative N, the matches are counted from the end of string. Chris@16: \return Chris@16: An \c iterator_range delimiting the match. Chris@16: Returned iterator is either \c Range1T::iterator or Chris@16: \c Range1T::const_iterator, depending on the constness of Chris@16: the input parameter. Chris@16: */ Chris@16: template Chris@16: inline iterator_range< Chris@16: BOOST_STRING_TYPENAME range_iterator::type> Chris@16: find_nth( Chris@16: Range1T& Input, Chris@16: const Range2T& Search, Chris@16: int Nth) Chris@16: { Chris@16: return ::boost::algorithm::find(Input, ::boost::algorithm::nth_finder(Search,Nth)); Chris@16: } Chris@16: Chris@16: //! Find n-th algorithm ( case insensitive ). Chris@16: /*! Chris@16: Search for the n-th (zero-indexed) occurrence of the substring in the Chris@16: input. Searching is case insensitive. Chris@16: Chris@16: \param Input A string which will be searched. Chris@16: \param Search A substring to be searched for. Chris@16: \param Nth An index (zero-indexed) of the match to be found. Chris@16: For negative N, the matches are counted from the end of string. Chris@16: \param Loc A locale used for case insensitive comparison Chris@16: \return Chris@16: An \c iterator_range delimiting the match. Chris@16: Returned iterator is either \c Range1T::iterator or Chris@16: \c Range1T::const_iterator, depending on the constness of Chris@16: the input parameter. Chris@16: Chris@16: Chris@16: \note This function provides the strong exception-safety guarantee Chris@16: */ Chris@16: template Chris@16: inline iterator_range< Chris@16: BOOST_STRING_TYPENAME range_iterator::type> Chris@16: ifind_nth( Chris@16: Range1T& Input, Chris@16: const Range2T& Search, Chris@16: int Nth, Chris@16: const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return ::boost::algorithm::find(Input, ::boost::algorithm::nth_finder(Search,Nth,is_iequal(Loc))); Chris@16: } Chris@16: Chris@16: // find_head ----------------------------------------------------------------------// Chris@16: Chris@16: //! Find head algorithm Chris@16: /*! Chris@16: Get the head of the input. Head is a prefix of the string of the Chris@16: given size. If the input is shorter then required, whole input is considered Chris@16: to be the head. Chris@16: Chris@16: \param Input An input string Chris@16: \param N Length of the head Chris@16: For N>=0, at most N characters are extracted. Chris@16: For N<0, at most size(Input)-|N| characters are extracted. Chris@16: \return Chris@16: An \c iterator_range delimiting the match. Chris@16: Returned iterator is either \c Range1T::iterator or Chris@16: \c Range1T::const_iterator, depending on the constness of Chris@16: the input parameter. Chris@16: Chris@16: \note This function provides the strong exception-safety guarantee Chris@16: */ Chris@16: template Chris@16: inline iterator_range< Chris@16: BOOST_STRING_TYPENAME range_iterator::type> Chris@16: find_head( Chris@16: RangeT& Input, Chris@16: int N) Chris@16: { Chris@16: return ::boost::algorithm::find(Input, ::boost::algorithm::head_finder(N)); Chris@16: } Chris@16: Chris@16: // find_tail ----------------------------------------------------------------------// Chris@16: Chris@16: //! Find tail algorithm Chris@16: /*! Chris@16: Get the tail of the input. Tail is a suffix of the string of the Chris@16: given size. If the input is shorter then required, whole input is considered Chris@16: to be the tail. Chris@16: Chris@16: \param Input An input string Chris@16: \param N Length of the tail. Chris@16: For N>=0, at most N characters are extracted. Chris@16: For N<0, at most size(Input)-|N| characters are extracted. Chris@16: \return Chris@16: An \c iterator_range delimiting the match. Chris@16: Returned iterator is either \c RangeT::iterator or Chris@16: \c RangeT::const_iterator, depending on the constness of Chris@16: the input parameter. Chris@16: Chris@16: Chris@16: \note This function provides the strong exception-safety guarantee Chris@16: */ Chris@16: template Chris@16: inline iterator_range< Chris@16: BOOST_STRING_TYPENAME range_iterator::type> Chris@16: find_tail( Chris@16: RangeT& Input, Chris@16: int N) Chris@16: { Chris@16: return ::boost::algorithm::find(Input, ::boost::algorithm::tail_finder(N)); Chris@16: } Chris@16: Chris@16: // find_token --------------------------------------------------------------------// Chris@16: Chris@16: //! Find token algorithm Chris@16: /*! Chris@16: Look for a given token in the string. Token is a character that matches the Chris@16: given predicate. Chris@16: If the "token compress mode" is enabled, adjacent tokens are considered to be one match. Chris@16: Chris@16: \param Input A input string. Chris@16: \param Pred A unary predicate to identify a token Chris@16: \param eCompress Enable/Disable compressing of adjacent tokens Chris@16: \return Chris@16: An \c iterator_range delimiting the match. Chris@16: Returned iterator is either \c RangeT::iterator or Chris@16: \c RangeT::const_iterator, depending on the constness of Chris@16: the input parameter. Chris@16: Chris@16: \note This function provides the strong exception-safety guarantee Chris@16: */ Chris@16: template Chris@16: inline iterator_range< Chris@16: BOOST_STRING_TYPENAME range_iterator::type> Chris@16: find_token( Chris@16: RangeT& Input, Chris@16: PredicateT Pred, Chris@16: token_compress_mode_type eCompress=token_compress_off) Chris@16: { Chris@16: return ::boost::algorithm::find(Input, ::boost::algorithm::token_finder(Pred, eCompress)); Chris@16: } Chris@16: Chris@16: } // namespace algorithm Chris@16: Chris@16: // pull names to the boost namespace Chris@16: using algorithm::find; Chris@16: using algorithm::find_first; Chris@16: using algorithm::ifind_first; Chris@16: using algorithm::find_last; Chris@16: using algorithm::ifind_last; Chris@16: using algorithm::find_nth; Chris@16: using algorithm::ifind_nth; Chris@16: using algorithm::find_head; Chris@16: using algorithm::find_tail; Chris@16: using algorithm::find_token; Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: Chris@16: #endif // BOOST_STRING_FIND_HPP