Chris@16: // Boost string_algo library find_format.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_FORMAT_HPP Chris@16: #define BOOST_STRING_FIND_FORMAT_HPP Chris@16: Chris@16: #include Chris@16: #include 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 generic replace algorithms. Each algorithm replaces Chris@16: part(s) of the input. The part to be replaced is looked up using a Finder object. Chris@16: Result of finding is then used by a Formatter object to generate the replacement. Chris@16: */ Chris@16: Chris@16: namespace boost { Chris@16: namespace algorithm { Chris@16: Chris@16: // generic replace -----------------------------------------------------------------// Chris@16: Chris@16: //! Generic replace algorithm Chris@16: /*! Chris@16: Use the Finder to search for a substring. Use the Formatter to format Chris@16: this substring and replace it in the input. Chris@16: The result is a modified copy of the input. It is returned as a sequence Chris@16: or copied to the output iterator. Chris@16: Chris@16: \param Output An output iterator to which the result will be copied Chris@16: \param Input An input sequence Chris@16: \param Finder A Finder object used to search for a match to be replaced Chris@16: \param Formatter A Formatter object used to format a match Chris@16: \return An output iterator pointing just after the last inserted character or Chris@16: a modified copy of the input Chris@16: Chris@16: \note The second variant of this function provides the strong exception-safety guarantee Chris@16: */ Chris@16: template< Chris@16: typename OutputIteratorT, Chris@16: typename RangeT, Chris@16: typename FinderT, Chris@16: typename FormatterT> Chris@16: inline OutputIteratorT find_format_copy( Chris@16: OutputIteratorT Output, Chris@16: const RangeT& Input, Chris@16: FinderT Finder, Chris@16: FormatterT Formatter ) Chris@16: { Chris@16: // Concept check Chris@16: BOOST_CONCEPT_ASSERT(( Chris@16: FinderConcept< Chris@16: FinderT, Chris@16: BOOST_STRING_TYPENAME range_const_iterator::type> Chris@16: )); Chris@16: BOOST_CONCEPT_ASSERT(( Chris@16: FormatterConcept< Chris@16: FormatterT, Chris@16: FinderT,BOOST_STRING_TYPENAME range_const_iterator::type> Chris@16: )); Chris@16: Chris@16: iterator_range::type> lit_input(::boost::as_literal(Input)); Chris@16: Chris@16: return detail::find_format_copy_impl( Chris@16: Output, Chris@16: lit_input, Chris@16: Formatter, Chris@16: Finder( ::boost::begin(lit_input), ::boost::end(lit_input) ) ); Chris@16: } Chris@16: Chris@16: //! Generic replace algorithm Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template< Chris@16: typename SequenceT, Chris@16: typename FinderT, Chris@16: typename FormatterT> Chris@16: inline SequenceT find_format_copy( Chris@16: const SequenceT& Input, Chris@16: FinderT Finder, Chris@16: FormatterT Formatter ) Chris@16: { Chris@16: // Concept check Chris@16: BOOST_CONCEPT_ASSERT(( Chris@16: FinderConcept< Chris@16: FinderT, Chris@16: BOOST_STRING_TYPENAME range_const_iterator::type> Chris@16: )); Chris@16: BOOST_CONCEPT_ASSERT(( Chris@16: FormatterConcept< Chris@16: FormatterT, Chris@16: FinderT,BOOST_STRING_TYPENAME range_const_iterator::type> Chris@16: )); Chris@16: Chris@16: return detail::find_format_copy_impl( Chris@16: Input, Chris@16: Formatter, Chris@16: Finder(::boost::begin(Input), ::boost::end(Input))); Chris@16: } Chris@16: Chris@16: //! Generic replace algorithm Chris@16: /*! Chris@16: Use the Finder to search for a substring. Use the Formatter to format Chris@16: this substring and replace it in the input. The input is modified in-place. Chris@16: Chris@16: \param Input An input sequence Chris@16: \param Finder A Finder object used to search for a match to be replaced Chris@16: \param Formatter A Formatter object used to format a match Chris@16: */ Chris@16: template< Chris@16: typename SequenceT, Chris@16: typename FinderT, Chris@16: typename FormatterT> Chris@16: inline void find_format( Chris@16: SequenceT& Input, Chris@16: FinderT Finder, Chris@16: FormatterT Formatter) Chris@16: { Chris@16: // Concept check Chris@16: BOOST_CONCEPT_ASSERT(( Chris@16: FinderConcept< Chris@16: FinderT, Chris@16: BOOST_STRING_TYPENAME range_const_iterator::type> Chris@16: )); Chris@16: BOOST_CONCEPT_ASSERT(( Chris@16: FormatterConcept< Chris@16: FormatterT, Chris@16: FinderT,BOOST_STRING_TYPENAME range_const_iterator::type> Chris@16: )); Chris@16: Chris@16: detail::find_format_impl( Chris@16: Input, Chris@16: Formatter, Chris@16: Finder(::boost::begin(Input), ::boost::end(Input))); Chris@16: } Chris@16: Chris@16: Chris@16: // find_format_all generic ----------------------------------------------------------------// Chris@16: Chris@16: //! Generic replace all algorithm Chris@16: /*! Chris@16: Use the Finder to search for a substring. Use the Formatter to format Chris@16: this substring and replace it in the input. Repeat this for all matching Chris@16: substrings. Chris@16: The result is a modified copy of the input. It is returned as a sequence Chris@16: or copied to the output iterator. Chris@16: Chris@16: \param Output An output iterator to which the result will be copied Chris@16: \param Input An input sequence Chris@16: \param Finder A Finder object used to search for a match to be replaced Chris@16: \param Formatter A Formatter object used to format a match Chris@16: \return An output iterator pointing just after the last inserted character or Chris@16: a modified copy of the input Chris@16: Chris@16: \note The second variant of this function provides the strong exception-safety guarantee Chris@16: */ Chris@16: template< Chris@16: typename OutputIteratorT, Chris@16: typename RangeT, Chris@16: typename FinderT, Chris@16: typename FormatterT> Chris@16: inline OutputIteratorT find_format_all_copy( Chris@16: OutputIteratorT Output, Chris@16: const RangeT& Input, Chris@16: FinderT Finder, Chris@16: FormatterT Formatter) Chris@16: { Chris@16: // Concept check Chris@16: BOOST_CONCEPT_ASSERT(( Chris@16: FinderConcept< Chris@16: FinderT, Chris@16: BOOST_STRING_TYPENAME range_const_iterator::type> Chris@16: )); Chris@16: BOOST_CONCEPT_ASSERT(( Chris@16: FormatterConcept< Chris@16: FormatterT, Chris@16: FinderT,BOOST_STRING_TYPENAME range_const_iterator::type> Chris@16: )); Chris@16: Chris@16: iterator_range::type> lit_input(::boost::as_literal(Input)); Chris@16: Chris@16: return detail::find_format_all_copy_impl( Chris@16: Output, Chris@16: lit_input, Chris@16: Finder, Chris@16: Formatter, Chris@16: Finder(::boost::begin(lit_input), ::boost::end(lit_input))); Chris@16: } Chris@16: Chris@16: //! Generic replace all algorithm Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template< Chris@16: typename SequenceT, Chris@16: typename FinderT, Chris@16: typename FormatterT > Chris@16: inline SequenceT find_format_all_copy( Chris@16: const SequenceT& Input, Chris@16: FinderT Finder, Chris@16: FormatterT Formatter ) Chris@16: { Chris@16: // Concept check Chris@16: BOOST_CONCEPT_ASSERT(( Chris@16: FinderConcept< Chris@16: FinderT, Chris@16: BOOST_STRING_TYPENAME range_const_iterator::type> Chris@16: )); Chris@16: BOOST_CONCEPT_ASSERT(( Chris@16: FormatterConcept< Chris@16: FormatterT, Chris@16: FinderT,BOOST_STRING_TYPENAME range_const_iterator::type> Chris@16: )); Chris@16: Chris@16: return detail::find_format_all_copy_impl( Chris@16: Input, Chris@16: Finder, Chris@16: Formatter, Chris@16: Finder( ::boost::begin(Input), ::boost::end(Input) ) ); Chris@16: } Chris@16: Chris@16: //! Generic replace all algorithm Chris@16: /*! Chris@16: Use the Finder to search for a substring. Use the Formatter to format Chris@16: this substring and replace it in the input. Repeat this for all matching Chris@16: substrings.The input is modified in-place. Chris@16: Chris@16: \param Input An input sequence Chris@16: \param Finder A Finder object used to search for a match to be replaced Chris@16: \param Formatter A Formatter object used to format a match Chris@16: */ Chris@16: template< Chris@16: typename SequenceT, Chris@16: typename FinderT, Chris@16: typename FormatterT > Chris@16: inline void find_format_all( Chris@16: SequenceT& Input, Chris@16: FinderT Finder, Chris@16: FormatterT Formatter ) Chris@16: { Chris@16: // Concept check Chris@16: BOOST_CONCEPT_ASSERT(( Chris@16: FinderConcept< Chris@16: FinderT, Chris@16: BOOST_STRING_TYPENAME range_const_iterator::type> Chris@16: )); Chris@16: BOOST_CONCEPT_ASSERT(( Chris@16: FormatterConcept< Chris@16: FormatterT, Chris@16: FinderT,BOOST_STRING_TYPENAME range_const_iterator::type> Chris@16: )); Chris@16: Chris@16: detail::find_format_all_impl( Chris@16: Input, Chris@16: Finder, Chris@16: Formatter, Chris@16: Finder(::boost::begin(Input), ::boost::end(Input))); Chris@16: Chris@16: } Chris@16: Chris@16: } // namespace algorithm Chris@16: Chris@16: // pull the names to the boost namespace Chris@16: using algorithm::find_format_copy; Chris@16: using algorithm::find_format; Chris@16: using algorithm::find_format_all_copy; Chris@16: using algorithm::find_format_all; Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: Chris@16: #endif // BOOST_STRING_FIND_FORMAT_HPP