File indexing completed on 2025-01-18 09:28:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_STRING_DETAIL_SEQUENCE_HPP
0012 #define BOOST_STRING_DETAIL_SEQUENCE_HPP
0013
0014 #include <boost/algorithm/string/config.hpp>
0015 #include <boost/mpl/bool.hpp>
0016 #include <boost/mpl/logical.hpp>
0017 #include <boost/range/begin.hpp>
0018 #include <boost/range/end.hpp>
0019
0020 #include <boost/algorithm/string/sequence_traits.hpp>
0021
0022 namespace boost {
0023 namespace algorithm {
0024 namespace detail {
0025
0026
0027
0028 template< typename InputT, typename ForwardIteratorT >
0029 inline void insert(
0030 InputT& Input,
0031 BOOST_STRING_TYPENAME InputT::iterator At,
0032 ForwardIteratorT Begin,
0033 ForwardIteratorT End )
0034 {
0035 Input.insert( At, Begin, End );
0036 }
0037
0038 template< typename InputT, typename InsertT >
0039 inline void insert(
0040 InputT& Input,
0041 BOOST_STRING_TYPENAME InputT::iterator At,
0042 const InsertT& Insert )
0043 {
0044 ::boost::algorithm::detail::insert( Input, At, ::boost::begin(Insert), ::boost::end(Insert) );
0045 }
0046
0047
0048
0049
0050
0051
0052
0053 template< typename InputT >
0054 inline typename InputT::iterator erase(
0055 InputT& Input,
0056 BOOST_STRING_TYPENAME InputT::iterator From,
0057 BOOST_STRING_TYPENAME InputT::iterator To )
0058 {
0059 return Input.erase( From, To );
0060 }
0061
0062
0063
0064
0065
0066 template< bool HasConstTimeOperations >
0067 struct replace_const_time_helper
0068 {
0069 template< typename InputT, typename ForwardIteratorT >
0070 void operator()(
0071 InputT& Input,
0072 BOOST_STRING_TYPENAME InputT::iterator From,
0073 BOOST_STRING_TYPENAME InputT::iterator To,
0074 ForwardIteratorT Begin,
0075 ForwardIteratorT End )
0076 {
0077
0078 ForwardIteratorT InsertIt=Begin;
0079 BOOST_STRING_TYPENAME InputT::iterator InputIt=From;
0080 for(; InsertIt!=End && InputIt!=To; InsertIt++, InputIt++ )
0081 {
0082 *InputIt=*InsertIt;
0083 }
0084
0085 if ( InsertIt!=End )
0086 {
0087
0088 Input.insert( InputIt, InsertIt, End );
0089 }
0090 else
0091 {
0092 if ( InputIt!=To )
0093 {
0094
0095 Input.erase( InputIt, To );
0096 }
0097 }
0098 }
0099 };
0100
0101 template<>
0102 struct replace_const_time_helper< true >
0103 {
0104
0105 template< typename InputT, typename ForwardIteratorT >
0106 void operator()(
0107 InputT& Input,
0108 BOOST_STRING_TYPENAME InputT::iterator From,
0109 BOOST_STRING_TYPENAME InputT::iterator To,
0110 ForwardIteratorT Begin,
0111 ForwardIteratorT End )
0112 {
0113 BOOST_STRING_TYPENAME InputT::iterator At=Input.erase( From, To );
0114 if ( Begin!=End )
0115 {
0116 if(!Input.empty())
0117 {
0118 Input.insert( At, Begin, End );
0119 }
0120 else
0121 {
0122 Input.insert( Input.begin(), Begin, End );
0123 }
0124 }
0125 }
0126 };
0127
0128
0129 template< bool HasNative >
0130 struct replace_native_helper
0131 {
0132 template< typename InputT, typename ForwardIteratorT >
0133 void operator()(
0134 InputT& Input,
0135 BOOST_STRING_TYPENAME InputT::iterator From,
0136 BOOST_STRING_TYPENAME InputT::iterator To,
0137 ForwardIteratorT Begin,
0138 ForwardIteratorT End )
0139 {
0140 replace_const_time_helper<
0141 boost::mpl::and_<
0142 has_const_time_insert<InputT>,
0143 has_const_time_erase<InputT> >::value >()(
0144 Input, From, To, Begin, End );
0145 }
0146 };
0147
0148
0149 template<>
0150 struct replace_native_helper< true >
0151 {
0152 template< typename InputT, typename ForwardIteratorT >
0153 void operator()(
0154 InputT& Input,
0155 BOOST_STRING_TYPENAME InputT::iterator From,
0156 BOOST_STRING_TYPENAME InputT::iterator To,
0157 ForwardIteratorT Begin,
0158 ForwardIteratorT End )
0159 {
0160 Input.replace( From, To, Begin, End );
0161 }
0162 };
0163
0164
0165
0166 template< typename InputT, typename ForwardIteratorT >
0167 inline void replace(
0168 InputT& Input,
0169 BOOST_STRING_TYPENAME InputT::iterator From,
0170 BOOST_STRING_TYPENAME InputT::iterator To,
0171 ForwardIteratorT Begin,
0172 ForwardIteratorT End )
0173 {
0174 replace_native_helper< has_native_replace<InputT>::value >()(
0175 Input, From, To, Begin, End );
0176 }
0177
0178 template< typename InputT, typename InsertT >
0179 inline void replace(
0180 InputT& Input,
0181 BOOST_STRING_TYPENAME InputT::iterator From,
0182 BOOST_STRING_TYPENAME InputT::iterator To,
0183 const InsertT& Insert )
0184 {
0185 if(From!=To)
0186 {
0187 ::boost::algorithm::detail::replace( Input, From, To, ::boost::begin(Insert), ::boost::end(Insert) );
0188 }
0189 else
0190 {
0191 ::boost::algorithm::detail::insert( Input, From, ::boost::begin(Insert), ::boost::end(Insert) );
0192 }
0193 }
0194
0195 }
0196 }
0197 }
0198
0199
0200 #endif