Chris@16: // Boost string_algo library split.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_SPLIT_HPP Chris@16: #define BOOST_STRING_SPLIT_HPP Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: /*! \file Chris@16: Defines basic split algorithms. Chris@16: Split algorithms can be used to divide a string Chris@16: into several parts according to given criteria. Chris@16: Chris@16: Each part is copied and added as a new element to the Chris@16: output container. Chris@16: Thus the result container must be able to hold copies Chris@16: of the matches (in a compatible structure like std::string) or Chris@16: a reference to it (e.g. using the iterator range class). Chris@16: Examples of such a container are \c std::vector Chris@16: or \c std::list> Chris@16: */ Chris@16: Chris@16: namespace boost { Chris@16: namespace algorithm { Chris@16: Chris@16: // find_all ------------------------------------------------------------// Chris@16: Chris@16: //! Find all algorithm Chris@16: /*! Chris@16: This algorithm finds all occurrences of the search string Chris@16: in the input. Chris@16: Chris@16: Each part is copied and added as a new element to the Chris@16: output container. Chris@16: Thus the result container must be able to hold copies Chris@16: of the matches (in a compatible structure like std::string) or Chris@16: a reference to it (e.g. using the iterator range class). Chris@16: Examples of such a container are \c std::vector Chris@16: or \c std::list> Chris@16: Chris@16: \param Result A container that can hold copies of references to the substrings Chris@16: \param Input A container which will be searched. Chris@16: \param Search A substring to be searched for. Chris@16: \return A reference the result Chris@16: Chris@16: \note Prior content of the result will be overwritten. Chris@16: Chris@16: \note This function provides the strong exception-safety guarantee Chris@16: */ Chris@16: template< typename SequenceSequenceT, typename Range1T, typename Range2T > Chris@16: inline SequenceSequenceT& find_all( Chris@16: SequenceSequenceT& Result, Chris@16: Range1T& Input, Chris@16: const Range2T& Search) Chris@16: { Chris@16: return ::boost::algorithm::iter_find( Chris@16: Result, Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search) ); Chris@16: } Chris@16: Chris@16: //! Find all algorithm ( case insensitive ) Chris@16: /*! Chris@16: This algorithm finds all occurrences of the search string Chris@16: in the input. Chris@16: Each part is copied and added as a new element to the Chris@16: output container. Thus the result container must be able to hold copies Chris@16: of the matches (in a compatible structure like std::string) or Chris@16: a reference to it (e.g. using the iterator range class). Chris@16: Examples of such a container are \c std::vector Chris@16: or \c std::list> Chris@16: Chris@16: Searching is case insensitive. Chris@16: Chris@16: \param Result A container that can hold copies of references to the substrings Chris@16: \param Input A container 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 A reference the result Chris@16: Chris@16: \note Prior content of the result will be overwritten. Chris@16: Chris@16: \note This function provides the strong exception-safety guarantee Chris@16: */ Chris@16: template< typename SequenceSequenceT, typename Range1T, typename Range2T > Chris@16: inline SequenceSequenceT& ifind_all( Chris@16: SequenceSequenceT& Result, Chris@16: Range1T& Input, Chris@16: const Range2T& Search, Chris@16: const std::locale& Loc=std::locale() ) Chris@16: { Chris@16: return ::boost::algorithm::iter_find( Chris@16: Result, Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search, is_iequal(Loc) ) ); Chris@16: } Chris@16: Chris@16: Chris@16: // tokenize -------------------------------------------------------------// Chris@16: Chris@16: //! Split algorithm Chris@16: /*! Chris@16: Tokenize expression. This function is equivalent to C strtok. Input Chris@16: sequence is split into tokens, separated by separators. Separators Chris@16: are given by means of the predicate. Chris@16: Chris@16: Each part is copied and added as a new element to the Chris@16: output container. Chris@16: Thus the result container must be able to hold copies Chris@16: of the matches (in a compatible structure like std::string) or Chris@16: a reference to it (e.g. using the iterator range class). Chris@16: Examples of such a container are \c std::vector Chris@16: or \c std::list> Chris@16: Chris@16: \param Result A container that can hold copies of references to the substrings Chris@16: \param Input A container which will be searched. Chris@16: \param Pred A predicate to identify separators. This predicate is Chris@16: supposed to return true if a given element is a separator. Chris@16: \param eCompress If eCompress argument is set to token_compress_on, adjacent Chris@16: separators are merged together. Otherwise, every two separators Chris@16: delimit a token. Chris@16: \return A reference the result Chris@16: Chris@16: \note Prior content of the result will be overwritten. Chris@16: Chris@16: \note This function provides the strong exception-safety guarantee Chris@16: */ Chris@16: template< typename SequenceSequenceT, typename RangeT, typename PredicateT > Chris@16: inline SequenceSequenceT& split( Chris@16: SequenceSequenceT& Result, 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::iter_split( Chris@16: Result, Chris@16: Input, Chris@16: ::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_all; Chris@16: using algorithm::ifind_all; Chris@16: using algorithm::split; Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: Chris@16: #endif // BOOST_STRING_SPLIT_HPP Chris@16: