Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 09:55:54

0001 //  Boost string_algo library find_format.hpp header file  ---------------------------//
0002 
0003 //  Copyright Pavol Droba 2002-2003.
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 //    (See accompanying file LICENSE_1_0.txt or copy at
0007 //          http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 //  See http://www.boost.org/ for updates, documentation, and revision history.
0010 
0011 #ifndef BOOST_STRING_FIND_FORMAT_HPP
0012 #define BOOST_STRING_FIND_FORMAT_HPP
0013 
0014 #include <deque>
0015 #include <boost/range/iterator_range_core.hpp>
0016 #include <boost/range/begin.hpp>
0017 #include <boost/range/end.hpp>
0018 #include <boost/range/const_iterator.hpp>
0019 #include <boost/range/as_literal.hpp>
0020 
0021 #include <boost/algorithm/string/concept.hpp>
0022 #include <boost/algorithm/string/detail/find_format.hpp>
0023 #include <boost/algorithm/string/detail/find_format_all.hpp>
0024 
0025 /*! \file
0026     Defines generic replace algorithms. Each algorithm replaces
0027     part(s) of the input. The part to be replaced is looked up using a Finder object.
0028     Result of finding is then used by a Formatter object to generate the replacement.
0029 */
0030 
0031 namespace boost {
0032     namespace algorithm {
0033 
0034 // generic replace  -----------------------------------------------------------------//
0035 
0036         //! Generic replace algorithm
0037         /*!
0038             Use the Finder to search for a substring. Use the Formatter to format
0039             this substring and replace it in the input.
0040             The result is a modified copy of the input. It is returned as a sequence 
0041             or copied to the output iterator.
0042 
0043             \param Output An output iterator to which the result will be copied
0044             \param Input An input sequence
0045             \param Finder A Finder object used to search for a match to be replaced
0046             \param Formatter A Formatter object used to format a match
0047             \return An output iterator pointing just after the last inserted character or
0048                 a modified copy of the input
0049 
0050             \note The second variant of this function provides the strong exception-safety guarantee
0051         */
0052         template< 
0053             typename OutputIteratorT,
0054             typename RangeT,
0055             typename FinderT,
0056             typename FormatterT>
0057         inline OutputIteratorT find_format_copy(
0058             OutputIteratorT Output,
0059             const RangeT& Input,
0060             FinderT Finder,
0061             FormatterT Formatter )
0062         {
0063             // Concept check
0064             BOOST_CONCEPT_ASSERT((
0065                 FinderConcept<
0066                     FinderT,
0067                     BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type>
0068                 ));
0069             BOOST_CONCEPT_ASSERT((
0070                 FormatterConcept<
0071                     FormatterT,
0072                     FinderT,BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type>
0073                 ));
0074 
0075             iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_input(::boost::as_literal(Input));
0076 
0077             return detail::find_format_copy_impl(
0078                 Output,
0079                 lit_input,
0080                 Formatter,
0081                 Finder( ::boost::begin(lit_input), ::boost::end(lit_input) ) );
0082         }
0083 
0084         //! Generic replace algorithm
0085         /*!
0086             \overload
0087         */
0088         template< 
0089             typename SequenceT, 
0090             typename FinderT,
0091             typename FormatterT>
0092         inline SequenceT find_format_copy(
0093             const SequenceT& Input,
0094             FinderT Finder,
0095             FormatterT Formatter )
0096         {
0097             // Concept check
0098             BOOST_CONCEPT_ASSERT((
0099                 FinderConcept<
0100                     FinderT,
0101                     BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
0102                 ));
0103             BOOST_CONCEPT_ASSERT((
0104                 FormatterConcept<
0105                     FormatterT,
0106                     FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
0107                 ));
0108 
0109             return detail::find_format_copy_impl(
0110                 Input,
0111                 Formatter,
0112                 Finder(::boost::begin(Input), ::boost::end(Input)));
0113         }
0114 
0115         //! Generic replace algorithm
0116         /*!
0117             Use the Finder to search for a substring. Use the Formatter to format
0118             this substring and replace it in the input. The input is modified in-place.
0119 
0120             \param Input An input sequence
0121             \param Finder A Finder object used to search for a match to be replaced
0122             \param Formatter A Formatter object used to format a match
0123         */
0124         template<
0125             typename SequenceT,
0126             typename FinderT,
0127             typename FormatterT>
0128         inline void find_format( 
0129             SequenceT& Input,
0130             FinderT Finder,
0131             FormatterT Formatter)
0132         {
0133             // Concept check
0134             BOOST_CONCEPT_ASSERT((
0135                 FinderConcept<
0136                     FinderT,
0137                     BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
0138                 ));
0139             BOOST_CONCEPT_ASSERT(( 
0140                 FormatterConcept<
0141                     FormatterT,
0142                     FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
0143                 ));
0144 
0145             detail::find_format_impl(
0146                 Input,
0147                 Formatter,
0148                 Finder(::boost::begin(Input), ::boost::end(Input)));
0149         }
0150 
0151 
0152 //  find_format_all generic ----------------------------------------------------------------//
0153 
0154         //! Generic replace all algorithm
0155         /*!
0156             Use the Finder to search for a substring. Use the Formatter to format
0157             this substring and replace it in the input. Repeat this for all matching
0158             substrings.
0159             The result is a modified copy of the input. It is returned as a sequence 
0160             or copied to the output iterator.
0161 
0162             \param Output An output iterator to which the result will be copied
0163             \param Input An input sequence
0164             \param Finder A Finder object used to search for a match to be replaced
0165             \param Formatter A Formatter object used to format a match
0166             \return An output iterator pointing just after the last inserted character or
0167                 a modified copy of the input
0168 
0169              \note The second variant of this function provides the strong exception-safety guarantee
0170         */
0171         template< 
0172             typename OutputIteratorT,
0173             typename RangeT,
0174             typename FinderT,
0175             typename FormatterT>
0176         inline OutputIteratorT find_format_all_copy(
0177             OutputIteratorT Output,
0178             const RangeT& Input,
0179             FinderT Finder,
0180             FormatterT Formatter)
0181         {
0182             // Concept check
0183             BOOST_CONCEPT_ASSERT(( 
0184                 FinderConcept<
0185                     FinderT,
0186                     BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type>
0187                 ));
0188             BOOST_CONCEPT_ASSERT(( 
0189                 FormatterConcept<
0190                     FormatterT,
0191                     FinderT,BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type>
0192                 ));
0193 
0194             iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_input(::boost::as_literal(Input));
0195 
0196             return detail::find_format_all_copy_impl(
0197                 Output,
0198                 lit_input,
0199                 Finder,
0200                 Formatter,
0201                 Finder(::boost::begin(lit_input), ::boost::end(lit_input)));
0202         }
0203 
0204         //! Generic replace all algorithm
0205         /*!
0206             \overload
0207         */
0208         template< 
0209             typename SequenceT, 
0210             typename FinderT,
0211             typename FormatterT >
0212         inline SequenceT find_format_all_copy(
0213             const SequenceT& Input,
0214             FinderT Finder,
0215             FormatterT Formatter )
0216         {
0217             // Concept check
0218             BOOST_CONCEPT_ASSERT((
0219                 FinderConcept<
0220                     FinderT,
0221                     BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
0222                 ));
0223             BOOST_CONCEPT_ASSERT((
0224                 FormatterConcept<
0225                     FormatterT,
0226                     FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
0227                 ));
0228 
0229             return detail::find_format_all_copy_impl(
0230                 Input,
0231                 Finder,
0232                 Formatter,
0233                 Finder( ::boost::begin(Input), ::boost::end(Input) ) );
0234         }
0235 
0236         //! Generic replace all algorithm
0237         /*!
0238             Use the Finder to search for a substring. Use the Formatter to format
0239             this substring and replace it in the input. Repeat this for all matching
0240             substrings.The input is modified in-place.
0241 
0242             \param Input An input sequence
0243             \param Finder A Finder object used to search for a match to be replaced
0244             \param Formatter A Formatter object used to format a match
0245         */
0246         template<
0247             typename SequenceT,
0248             typename FinderT,
0249             typename FormatterT >
0250         inline void find_format_all( 
0251             SequenceT& Input,
0252             FinderT Finder,
0253             FormatterT Formatter )
0254         {
0255             // Concept check
0256             BOOST_CONCEPT_ASSERT((
0257                 FinderConcept<
0258                     FinderT,
0259                     BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
0260                 ));
0261             BOOST_CONCEPT_ASSERT((
0262                 FormatterConcept<
0263                     FormatterT,
0264                     FinderT,BOOST_STRING_TYPENAME range_const_iterator<SequenceT>::type>
0265                 ));
0266 
0267             detail::find_format_all_impl(
0268                 Input,
0269                 Finder,
0270                 Formatter,
0271                 Finder(::boost::begin(Input), ::boost::end(Input)));
0272 
0273         }
0274 
0275     } // namespace algorithm
0276 
0277     // pull the names to the boost namespace
0278     using algorithm::find_format_copy;
0279     using algorithm::find_format;
0280     using algorithm::find_format_all_copy;
0281     using algorithm::find_format_all;
0282 
0283 } // namespace boost
0284 
0285 
0286 #endif  // BOOST_STRING_FIND_FORMAT_HPP