Chris@16: // Boost string_algo library replace.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_REPLACE_HPP Chris@16: #define BOOST_STRING_REPLACE_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: #include Chris@16: Chris@16: /*! \file Chris@16: Defines various replace algorithms. Each algorithm replaces Chris@16: part(s) of the input according to set of searching and replace criteria. Chris@16: */ Chris@16: Chris@16: namespace boost { Chris@16: namespace algorithm { Chris@16: Chris@16: // replace_range --------------------------------------------------------------------// Chris@16: Chris@16: //! Replace range algorithm Chris@16: /*! Chris@16: Replace the given range in the input string. 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 string Chris@16: \param SearchRange A range in the input to be substituted Chris@16: \param Format A substitute string 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 Range1T, Chris@16: typename Range2T> Chris@16: inline OutputIteratorT replace_range_copy( Chris@16: OutputIteratorT Output, Chris@16: const Range1T& Input, Chris@16: const iterator_range< Chris@16: BOOST_STRING_TYPENAME Chris@16: range_const_iterator::type>& SearchRange, Chris@16: const Range2T& Format) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Output, Chris@16: Input, Chris@16: ::boost::algorithm::range_finder(SearchRange), Chris@16: ::boost::algorithm::const_formatter(Format)); Chris@16: } Chris@16: Chris@16: //! Replace range algorithm Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline SequenceT replace_range_copy( Chris@16: const SequenceT& Input, Chris@16: const iterator_range< Chris@16: BOOST_STRING_TYPENAME Chris@16: range_const_iterator::type>& SearchRange, Chris@16: const RangeT& Format) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Input, Chris@16: ::boost::algorithm::range_finder(SearchRange), Chris@16: ::boost::algorithm::const_formatter(Format)); Chris@16: } Chris@16: Chris@16: //! Replace range algorithm Chris@16: /*! Chris@16: Replace the given range in the input string. Chris@16: The input sequence is modified in-place. Chris@16: Chris@16: \param Input An input string Chris@16: \param SearchRange A range in the input to be substituted Chris@16: \param Format A substitute string Chris@16: */ Chris@16: template Chris@16: inline void replace_range( Chris@16: SequenceT& Input, Chris@16: const iterator_range< Chris@16: BOOST_STRING_TYPENAME Chris@16: range_iterator::type>& SearchRange, Chris@16: const RangeT& Format) Chris@16: { Chris@16: ::boost::algorithm::find_format( Chris@16: Input, Chris@16: ::boost::algorithm::range_finder(SearchRange), Chris@16: ::boost::algorithm::const_formatter(Format)); Chris@16: } Chris@16: Chris@16: // replace_first --------------------------------------------------------------------// Chris@16: Chris@16: //! Replace first algorithm Chris@16: /*! Chris@16: Replace the first match of the search substring in the input Chris@16: with the format string. 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 string Chris@16: \param Search A substring to be searched for Chris@16: \param Format A substitute string 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 Range1T, Chris@16: typename Range2T, Chris@16: typename Range3T> Chris@16: inline OutputIteratorT replace_first_copy( Chris@16: OutputIteratorT Output, Chris@16: const Range1T& Input, Chris@16: const Range2T& Search, Chris@16: const Range3T& Format) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Output, Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace first algorithm Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline SequenceT replace_first_copy( Chris@16: const SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: const Range2T& Format ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace first algorithm Chris@16: /*! Chris@16: replace the first match of the search substring in the input Chris@16: with the format string. The input sequence is modified in-place. Chris@16: Chris@16: \param Input An input string Chris@16: \param Search A substring to be searched for Chris@16: \param Format A substitute string Chris@16: */ Chris@16: template Chris@16: inline void replace_first( Chris@16: SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: const Range2T& Format ) Chris@16: { Chris@16: ::boost::algorithm::find_format( Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: // replace_first ( case insensitive ) ---------------------------------------------// Chris@16: Chris@16: //! Replace first algorithm ( case insensitive ) Chris@16: /*! Chris@16: Replace the first match of the search substring in the input Chris@16: with the format string. 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: Searching is case insensitive. Chris@16: Chris@16: \param Output An output iterator to which the result will be copied Chris@16: \param Input An input string Chris@16: \param Search A substring to be searched for Chris@16: \param Format A substitute string Chris@16: \param Loc A locale used for case insensitive comparison 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 Range1T, Chris@16: typename Range2T, Chris@16: typename Range3T> Chris@16: inline OutputIteratorT ireplace_first_copy( Chris@16: OutputIteratorT Output, Chris@16: const Range1T& Input, Chris@16: const Range2T& Search, Chris@16: const Range3T& Format, Chris@16: const std::locale& Loc=std::locale() ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Output, Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search, is_iequal(Loc)), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace first algorithm ( case insensitive ) Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline SequenceT ireplace_first_copy( Chris@16: const SequenceT& Input, Chris@16: const Range2T& Search, Chris@16: const Range1T& Format, Chris@16: const std::locale& Loc=std::locale() ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search, is_iequal(Loc)), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace first algorithm ( case insensitive ) Chris@16: /*! Chris@16: Replace the first match of the search substring in the input Chris@16: with the format string. Input sequence is modified in-place. Chris@16: Searching is case insensitive. Chris@16: Chris@16: \param Input An input string Chris@16: \param Search A substring to be searched for Chris@16: \param Format A substitute string Chris@16: \param Loc A locale used for case insensitive comparison Chris@16: */ Chris@16: template Chris@16: inline void ireplace_first( Chris@16: SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: const Range2T& Format, Chris@16: const std::locale& Loc=std::locale() ) Chris@16: { Chris@16: ::boost::algorithm::find_format( Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search, is_iequal(Loc)), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: // replace_last --------------------------------------------------------------------// Chris@16: Chris@16: //! Replace last algorithm Chris@16: /*! Chris@16: Replace the last match of the search string in the input Chris@16: with the format string. 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 string Chris@16: \param Search A substring to be searched for Chris@16: \param Format A substitute string 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 Range1T, Chris@16: typename Range2T, Chris@16: typename Range3T> Chris@16: inline OutputIteratorT replace_last_copy( Chris@16: OutputIteratorT Output, Chris@16: const Range1T& Input, Chris@16: const Range2T& Search, Chris@16: const Range3T& Format ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Output, Chris@16: Input, Chris@16: ::boost::algorithm::last_finder(Search), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace last algorithm Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline SequenceT replace_last_copy( Chris@16: const SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: const Range2T& Format ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Input, Chris@16: ::boost::algorithm::last_finder(Search), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace last algorithm Chris@16: /*! Chris@16: Replace the last match of the search string in the input Chris@16: with the format string. Input sequence is modified in-place. Chris@16: Chris@16: \param Input An input string Chris@16: \param Search A substring to be searched for Chris@16: \param Format A substitute string Chris@16: */ Chris@16: template Chris@16: inline void replace_last( Chris@16: SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: const Range2T& Format ) Chris@16: { Chris@16: ::boost::algorithm::find_format( Chris@16: Input, Chris@16: ::boost::algorithm::last_finder(Search), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: // replace_last ( case insensitive ) -----------------------------------------------// Chris@16: Chris@16: //! Replace last algorithm ( case insensitive ) Chris@16: /*! Chris@16: Replace the last match of the search string in the input Chris@16: with the format string. 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: Searching is case insensitive. Chris@16: Chris@16: \param Output An output iterator to which the result will be copied Chris@16: \param Input An input string Chris@16: \param Search A substring to be searched for Chris@16: \param Format A substitute string Chris@16: \param Loc A locale used for case insensitive comparison 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 Range1T, Chris@16: typename Range2T, Chris@16: typename Range3T> Chris@16: inline OutputIteratorT ireplace_last_copy( Chris@16: OutputIteratorT Output, Chris@16: const Range1T& Input, Chris@16: const Range2T& Search, Chris@16: const Range3T& Format, Chris@16: const std::locale& Loc=std::locale() ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Output, Chris@16: Input, Chris@16: ::boost::algorithm::last_finder(Search, is_iequal(Loc)), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace last algorithm ( case insensitive ) Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline SequenceT ireplace_last_copy( Chris@16: const SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: const Range2T& Format, Chris@16: const std::locale& Loc=std::locale() ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Input, Chris@16: ::boost::algorithm::last_finder(Search, is_iequal(Loc)), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace last algorithm ( case insensitive ) Chris@16: /*! Chris@16: Replace the last match of the search string in the input Chris@16: with the format string.The input sequence is modified in-place. Chris@16: Searching is case insensitive. Chris@16: Chris@16: \param Input An input string Chris@16: \param Search A substring to be searched for Chris@16: \param Format A substitute string Chris@16: \param Loc A locale used for case insensitive comparison Chris@16: \return A reference to the modified input Chris@16: */ Chris@16: template Chris@16: inline void ireplace_last( Chris@16: SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: const Range2T& Format, Chris@16: const std::locale& Loc=std::locale() ) Chris@16: { Chris@16: ::boost::algorithm::find_format( Chris@16: Input, Chris@16: ::boost::algorithm::last_finder(Search, is_iequal(Loc)), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: // replace_nth --------------------------------------------------------------------// Chris@16: Chris@16: //! Replace nth algorithm Chris@16: /*! Chris@16: Replace an Nth (zero-indexed) match of the search string in the input Chris@16: with the format string. 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 string Chris@16: \param Search A substring to be searched for Chris@16: \param Nth An index of the match to be replaced. The index is 0-based. Chris@16: For negative N, matches are counted from the end of string. Chris@16: \param Format A substitute string 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 Range1T, Chris@16: typename Range2T, Chris@16: typename Range3T> Chris@16: inline OutputIteratorT replace_nth_copy( Chris@16: OutputIteratorT Output, Chris@16: const Range1T& Input, Chris@16: const Range2T& Search, Chris@16: int Nth, Chris@16: const Range3T& Format ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Output, Chris@16: Input, Chris@16: ::boost::algorithm::nth_finder(Search, Nth), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace nth algorithm Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline SequenceT replace_nth_copy( Chris@16: const SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: int Nth, Chris@16: const Range2T& Format ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Input, Chris@16: ::boost::algorithm::nth_finder(Search, Nth), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace nth algorithm Chris@16: /*! Chris@16: Replace an Nth (zero-indexed) match of the search string in the input Chris@16: with the format string. Input sequence is modified in-place. Chris@16: Chris@16: \param Input An input string Chris@16: \param Search A substring to be searched for Chris@16: \param Nth An index of the match to be replaced. The index is 0-based. Chris@16: For negative N, matches are counted from the end of string. Chris@16: \param Format A substitute string Chris@16: */ Chris@16: template Chris@16: inline void replace_nth( Chris@16: SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: int Nth, Chris@16: const Range2T& Format ) Chris@16: { Chris@16: ::boost::algorithm::find_format( Chris@16: Input, Chris@16: ::boost::algorithm::nth_finder(Search, Nth), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: // replace_nth ( case insensitive ) -----------------------------------------------// Chris@16: Chris@16: //! Replace nth algorithm ( case insensitive ) Chris@16: /*! Chris@16: Replace an Nth (zero-indexed) match of the search string in the input Chris@16: with the format string. 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: Searching is case insensitive. Chris@16: Chris@16: \param Output An output iterator to which the result will be copied Chris@16: \param Input An input string Chris@16: \param Search A substring to be searched for Chris@16: \param Nth An index of the match to be replaced. The index is 0-based. Chris@16: For negative N, matches are counted from the end of string. Chris@16: \param Format A substitute string Chris@16: \param Loc A locale used for case insensitive comparison 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 Range1T, Chris@16: typename Range2T, Chris@16: typename Range3T> Chris@16: inline OutputIteratorT ireplace_nth_copy( Chris@16: OutputIteratorT Output, Chris@16: const Range1T& Input, Chris@16: const Range2T& Search, Chris@16: int Nth, Chris@16: const Range3T& Format, Chris@16: const std::locale& Loc=std::locale() ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Output, Chris@16: Input, Chris@16: ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc) ), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace nth algorithm ( case insensitive ) Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline SequenceT ireplace_nth_copy( Chris@16: const SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: int Nth, Chris@16: const Range2T& Format, Chris@16: const std::locale& Loc=std::locale() ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Input, Chris@16: ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc)), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace nth algorithm ( case insensitive ) Chris@16: /*! Chris@16: Replace an Nth (zero-indexed) match of the search string in the input Chris@16: with the format string. Input sequence is modified in-place. Chris@16: Searching is case insensitive. Chris@16: Chris@16: \param Input An input string Chris@16: \param Search A substring to be searched for Chris@16: \param Nth An index of the match to be replaced. The index is 0-based. Chris@16: For negative N, matches are counted from the end of string. Chris@16: \param Format A substitute string Chris@16: \param Loc A locale used for case insensitive comparison Chris@16: */ Chris@16: template Chris@16: inline void ireplace_nth( Chris@16: SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: int Nth, Chris@16: const Range2T& Format, Chris@16: const std::locale& Loc=std::locale() ) Chris@16: { Chris@16: ::boost::algorithm::find_format( Chris@16: Input, Chris@16: ::boost::algorithm::nth_finder(Search, Nth, is_iequal(Loc)), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: // replace_all --------------------------------------------------------------------// Chris@16: Chris@16: //! Replace all algorithm Chris@16: /*! Chris@16: Replace all occurrences of the search string in the input Chris@16: with the format string. 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 string Chris@16: \param Search A substring to be searched for Chris@16: \param Format A substitute string 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 Range1T, Chris@16: typename Range2T, Chris@16: typename Range3T> Chris@16: inline OutputIteratorT replace_all_copy( Chris@16: OutputIteratorT Output, Chris@16: const Range1T& Input, Chris@16: const Range2T& Search, Chris@16: const Range3T& Format ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_all_copy( Chris@16: Output, Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace all algorithm Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline SequenceT replace_all_copy( Chris@16: const SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: const Range2T& Format ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_all_copy( Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace all algorithm Chris@16: /*! Chris@16: Replace all occurrences of the search string in the input Chris@16: with the format string. The input sequence is modified in-place. Chris@16: Chris@16: \param Input An input string Chris@16: \param Search A substring to be searched for Chris@16: \param Format A substitute string Chris@16: \return A reference to the modified input Chris@16: */ Chris@16: template Chris@16: inline void replace_all( Chris@16: SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: const Range2T& Format ) Chris@16: { Chris@16: ::boost::algorithm::find_format_all( Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: // replace_all ( case insensitive ) -----------------------------------------------// Chris@16: Chris@16: //! Replace all algorithm ( case insensitive ) Chris@16: /*! Chris@16: Replace all occurrences of the search string in the input Chris@16: with the format string. 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: Searching is case insensitive. Chris@16: Chris@16: \param Output An output iterator to which the result will be copied Chris@16: \param Input An input string Chris@16: \param Search A substring to be searched for Chris@16: \param Format A substitute string Chris@16: \param Loc A locale used for case insensitive comparison 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 Range1T, Chris@16: typename Range2T, Chris@16: typename Range3T> Chris@16: inline OutputIteratorT ireplace_all_copy( Chris@16: OutputIteratorT Output, Chris@16: const Range1T& Input, Chris@16: const Range2T& Search, Chris@16: const Range3T& Format, Chris@16: const std::locale& Loc=std::locale() ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_all_copy( Chris@16: Output, Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search, is_iequal(Loc)), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace all algorithm ( case insensitive ) Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline SequenceT ireplace_all_copy( Chris@16: const SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: const Range2T& Format, Chris@16: const std::locale& Loc=std::locale() ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_all_copy( Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search, is_iequal(Loc)), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace all algorithm ( case insensitive ) Chris@16: /*! Chris@16: Replace all occurrences of the search string in the input Chris@16: with the format string.The input sequence is modified in-place. Chris@16: Searching is case insensitive. Chris@16: Chris@16: \param Input An input string Chris@16: \param Search A substring to be searched for Chris@16: \param Format A substitute string Chris@16: \param Loc A locale used for case insensitive comparison Chris@16: */ Chris@16: template Chris@16: inline void ireplace_all( Chris@16: SequenceT& Input, Chris@16: const Range1T& Search, Chris@16: const Range2T& Format, Chris@16: const std::locale& Loc=std::locale() ) Chris@16: { Chris@16: ::boost::algorithm::find_format_all( Chris@16: Input, Chris@16: ::boost::algorithm::first_finder(Search, is_iequal(Loc)), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: // replace_head --------------------------------------------------------------------// Chris@16: Chris@16: //! Replace head algorithm Chris@16: /*! Chris@16: Replace the head of the input with the given format string. Chris@16: The head is a prefix of a string of given size. Chris@16: If the sequence is shorter then required, whole string if Chris@16: considered to be the head. 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 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, size(Input)-|N| characters are extracted. Chris@16: \param Format A substitute string 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 Range1T, Chris@16: typename Range2T> Chris@16: inline OutputIteratorT replace_head_copy( Chris@16: OutputIteratorT Output, Chris@16: const Range1T& Input, Chris@16: int N, Chris@16: const Range2T& Format ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Output, Chris@16: Input, Chris@16: ::boost::algorithm::head_finder(N), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace head algorithm Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline SequenceT replace_head_copy( Chris@16: const SequenceT& Input, Chris@16: int N, Chris@16: const RangeT& Format ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Input, Chris@16: ::boost::algorithm::head_finder(N), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace head algorithm Chris@16: /*! Chris@16: Replace the head of the input with the given format string. Chris@16: The head is a prefix of a string of given size. Chris@16: If the sequence is shorter then required, the whole string is Chris@16: considered to be the head. The input sequence is modified in-place. 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, size(Input)-|N| characters are extracted. Chris@16: \param Format A substitute string Chris@16: */ Chris@16: template Chris@16: inline void replace_head( Chris@16: SequenceT& Input, Chris@16: int N, Chris@16: const RangeT& Format ) Chris@16: { Chris@16: ::boost::algorithm::find_format( Chris@16: Input, Chris@16: ::boost::algorithm::head_finder(N), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: // replace_tail --------------------------------------------------------------------// Chris@16: Chris@16: //! Replace tail algorithm Chris@16: /*! Chris@16: Replace the tail of the input with the given format string. Chris@16: The tail is a suffix of a string of given size. Chris@16: If the sequence is shorter then required, whole string is Chris@16: considered to be the tail. 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 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, size(Input)-|N| characters are extracted. Chris@16: \param Format A substitute string 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 Range1T, Chris@16: typename Range2T> Chris@16: inline OutputIteratorT replace_tail_copy( Chris@16: OutputIteratorT Output, Chris@16: const Range1T& Input, Chris@16: int N, Chris@16: const Range2T& Format ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Output, Chris@16: Input, Chris@16: ::boost::algorithm::tail_finder(N), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace tail algorithm Chris@16: /*! Chris@16: \overload Chris@16: */ Chris@16: template Chris@16: inline SequenceT replace_tail_copy( Chris@16: const SequenceT& Input, Chris@16: int N, Chris@16: const RangeT& Format ) Chris@16: { Chris@16: return ::boost::algorithm::find_format_copy( Chris@16: Input, Chris@16: ::boost::algorithm::tail_finder(N), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: //! Replace tail algorithm Chris@16: /*! Chris@16: Replace the tail of the input with the given format sequence. Chris@16: The tail is a suffix of a string of given size. Chris@16: If the sequence is shorter then required, the whole string is Chris@16: considered to be the tail. The input sequence is modified in-place. 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, size(Input)-|N| characters are extracted. Chris@16: \param Format A substitute string Chris@16: */ Chris@16: template Chris@16: inline void replace_tail( Chris@16: SequenceT& Input, Chris@16: int N, Chris@16: const RangeT& Format ) Chris@16: { Chris@16: ::boost::algorithm::find_format( Chris@16: Input, Chris@16: ::boost::algorithm::tail_finder(N), Chris@16: ::boost::algorithm::const_formatter(Format) ); Chris@16: } Chris@16: Chris@16: } // namespace algorithm Chris@16: Chris@16: // pull names to the boost namespace Chris@16: using algorithm::replace_range_copy; Chris@16: using algorithm::replace_range; Chris@16: using algorithm::replace_first_copy; Chris@16: using algorithm::replace_first; Chris@16: using algorithm::ireplace_first_copy; Chris@16: using algorithm::ireplace_first; Chris@16: using algorithm::replace_last_copy; Chris@16: using algorithm::replace_last; Chris@16: using algorithm::ireplace_last_copy; Chris@16: using algorithm::ireplace_last; Chris@16: using algorithm::replace_nth_copy; Chris@16: using algorithm::replace_nth; Chris@16: using algorithm::ireplace_nth_copy; Chris@16: using algorithm::ireplace_nth; Chris@16: using algorithm::replace_all_copy; Chris@16: using algorithm::replace_all; Chris@16: using algorithm::ireplace_all_copy; Chris@16: using algorithm::ireplace_all; Chris@16: using algorithm::replace_head_copy; Chris@16: using algorithm::replace_head; Chris@16: using algorithm::replace_tail_copy; Chris@16: using algorithm::replace_tail; Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_REPLACE_HPP