Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:23

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_DETAIL_HPP
0012 #define BOOST_STRING_FIND_FORMAT_DETAIL_HPP
0013 
0014 #include <boost/algorithm/string/config.hpp>
0015 #include <boost/range/iterator_range_core.hpp>
0016 #include <boost/range/const_iterator.hpp>
0017 #include <boost/range/iterator.hpp>
0018 #include <boost/algorithm/string/detail/find_format_store.hpp>
0019 #include <boost/algorithm/string/detail/replace_storage.hpp>
0020 
0021 namespace boost {
0022     namespace algorithm {
0023         namespace detail {
0024 
0025 // find_format_copy (iterator variant) implementation -------------------------------//
0026 
0027            template< 
0028                 typename OutputIteratorT,
0029                 typename InputT,
0030                 typename FormatterT,
0031                 typename FindResultT,
0032                 typename FormatResultT >
0033             inline OutputIteratorT find_format_copy_impl2(
0034                 OutputIteratorT Output,
0035                 const InputT& Input,
0036                 FormatterT Formatter,
0037                 const FindResultT& FindResult,
0038                 const FormatResultT& FormatResult )
0039             {       
0040                 typedef find_format_store<
0041                     BOOST_STRING_TYPENAME 
0042                         range_const_iterator<InputT>::type, 
0043                         FormatterT,
0044                         FormatResultT > store_type;
0045 
0046                 // Create store for the find result
0047                 store_type M( FindResult, FormatResult, Formatter );
0048 
0049                 if ( !M )
0050                 {
0051                     // Match not found - return original sequence
0052                     Output = std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
0053                     return Output;
0054                 }
0055 
0056                 // Copy the beginning of the sequence
0057                 Output = std::copy( ::boost::begin(Input), ::boost::begin(M), Output );
0058                 // Format find result
0059                 // Copy formatted result
0060                 Output = std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output );
0061                 // Copy the rest of the sequence
0062                 Output = std::copy( M.end(), ::boost::end(Input), Output );
0063 
0064                 return Output;
0065             }
0066 
0067             template< 
0068                 typename OutputIteratorT,
0069                 typename InputT,
0070                 typename FormatterT,
0071                 typename FindResultT >
0072             inline OutputIteratorT find_format_copy_impl(
0073                 OutputIteratorT Output,
0074                 const InputT& Input,
0075                 FormatterT Formatter,
0076                 const FindResultT& FindResult )
0077             {   
0078                 if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
0079                     return ::boost::algorithm::detail::find_format_copy_impl2( 
0080                         Output,
0081                         Input,
0082                         Formatter,
0083                         FindResult,
0084                         Formatter(FindResult) );
0085                 } else {
0086                     return std::copy( ::boost::begin(Input), ::boost::end(Input), Output );
0087                 }
0088             }
0089 
0090  
0091 // find_format_copy implementation --------------------------------------------------//
0092 
0093            template< 
0094                 typename InputT, 
0095                 typename FormatterT,
0096                 typename FindResultT,
0097                 typename FormatResultT >
0098             inline InputT find_format_copy_impl2(
0099                 const InputT& Input,
0100                 FormatterT Formatter,
0101                 const FindResultT& FindResult,
0102                 const FormatResultT& FormatResult)
0103             {
0104                 typedef find_format_store<
0105                     BOOST_STRING_TYPENAME 
0106                         range_const_iterator<InputT>::type, 
0107                         FormatterT,
0108                         FormatResultT > store_type;
0109 
0110                 // Create store for the find result
0111                 store_type M( FindResult, FormatResult, Formatter );
0112 
0113                 if ( !M )
0114                 {
0115                     // Match not found - return original sequence
0116                     return InputT( Input );
0117                 }
0118 
0119                 InputT Output;
0120                 // Copy the beginning of the sequence
0121                 boost::algorithm::detail::insert( Output, ::boost::end(Output), ::boost::begin(Input), M.begin() );
0122                 // Copy formatted result
0123                 boost::algorithm::detail::insert( Output, ::boost::end(Output), M.format_result() );
0124                 // Copy the rest of the sequence
0125                 boost::algorithm::detail::insert( Output, ::boost::end(Output), M.end(), ::boost::end(Input) );
0126 
0127                 return Output;
0128             }
0129 
0130             template< 
0131                 typename InputT, 
0132                 typename FormatterT,
0133                 typename FindResultT >
0134             inline InputT find_format_copy_impl(
0135                 const InputT& Input,
0136                 FormatterT Formatter,
0137                 const FindResultT& FindResult)
0138             {
0139                 if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
0140                     return ::boost::algorithm::detail::find_format_copy_impl2(
0141                         Input,
0142                         Formatter,
0143                         FindResult,
0144                         Formatter(FindResult) );
0145                 } else {
0146                     return Input;
0147                 }
0148             }
0149 
0150  // replace implementation ----------------------------------------------------//
0151         
0152             template<
0153                 typename InputT,
0154                 typename FormatterT,
0155                 typename FindResultT,
0156                 typename FormatResultT >
0157             inline void find_format_impl2( 
0158                 InputT& Input,
0159                 FormatterT Formatter,
0160                 const FindResultT& FindResult,
0161                 const FormatResultT& FormatResult)
0162             {
0163                 typedef find_format_store<
0164                     BOOST_STRING_TYPENAME 
0165                         range_iterator<InputT>::type, 
0166                         FormatterT,
0167                         FormatResultT > store_type;
0168 
0169                 // Create store for the find result
0170                 store_type M( FindResult, FormatResult, Formatter );
0171 
0172                 if ( !M )
0173                 {
0174                     // Search not found - return original sequence
0175                     return;
0176                 }
0177 
0178                 // Replace match
0179                 ::boost::algorithm::detail::replace( Input, M.begin(), M.end(), M.format_result() );
0180             }
0181 
0182             template<
0183                 typename InputT,
0184                 typename FormatterT,
0185                 typename FindResultT >
0186             inline void find_format_impl( 
0187                 InputT& Input,
0188                 FormatterT Formatter,
0189                 const FindResultT& FindResult)
0190             {
0191                 if( ::boost::algorithm::detail::check_find_result(Input, FindResult) ) {
0192                     ::boost::algorithm::detail::find_format_impl2(
0193                         Input,
0194                         Formatter,
0195                         FindResult,
0196                         Formatter(FindResult) );
0197                 }
0198             }
0199 
0200         } // namespace detail
0201     } // namespace algorithm
0202 } // namespace boost
0203 
0204 #endif  // BOOST_STRING_FIND_FORMAT_DETAIL_HPP