123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #ifndef BOOST_STRING_DETAIL_SEQUENCE_HPP
- #define BOOST_STRING_DETAIL_SEQUENCE_HPP
- #include <boost/algorithm/string/config.hpp>
- #include <boost/mpl/bool.hpp>
- #include <boost/mpl/logical.hpp>
- #include <boost/range/begin.hpp>
- #include <boost/range/end.hpp>
- #include <boost/algorithm/string/sequence_traits.hpp>
- namespace boost {
- namespace algorithm {
- namespace detail {
-
- template< typename InputT, typename ForwardIteratorT >
- inline void insert(
- InputT& Input,
- BOOST_STRING_TYPENAME InputT::iterator At,
- ForwardIteratorT Begin,
- ForwardIteratorT End )
- {
- Input.insert( At, Begin, End );
- }
- template< typename InputT, typename InsertT >
- inline void insert(
- InputT& Input,
- BOOST_STRING_TYPENAME InputT::iterator At,
- const InsertT& Insert )
- {
- insert( Input, At, ::boost::begin(Insert), ::boost::end(Insert) );
- }
-
-
-
- template< typename InputT >
- inline typename InputT::iterator erase(
- InputT& Input,
- BOOST_STRING_TYPENAME InputT::iterator From,
- BOOST_STRING_TYPENAME InputT::iterator To )
- {
- return Input.erase( From, To );
- }
-
-
- template< bool HasConstTimeOperations >
- struct replace_const_time_helper
- {
- template< typename InputT, typename ForwardIteratorT >
- void operator()(
- InputT& Input,
- BOOST_STRING_TYPENAME InputT::iterator From,
- BOOST_STRING_TYPENAME InputT::iterator To,
- ForwardIteratorT Begin,
- ForwardIteratorT End )
- {
-
- ForwardIteratorT InsertIt=Begin;
- BOOST_STRING_TYPENAME InputT::iterator InputIt=From;
- for(; InsertIt!=End && InputIt!=To; InsertIt++, InputIt++ )
- {
- *InputIt=*InsertIt;
- }
- if ( InsertIt!=End )
- {
-
- Input.insert( InputIt, InsertIt, End );
- }
- else
- {
- if ( InputIt!=To )
- {
-
- Input.erase( InputIt, To );
- }
- }
- }
- };
- template<>
- struct replace_const_time_helper< true >
- {
-
- template< typename InputT, typename ForwardIteratorT >
- void operator()(
- InputT& Input,
- BOOST_STRING_TYPENAME InputT::iterator From,
- BOOST_STRING_TYPENAME InputT::iterator To,
- ForwardIteratorT Begin,
- ForwardIteratorT End )
- {
- BOOST_STRING_TYPENAME InputT::iterator At=Input.erase( From, To );
- if ( Begin!=End )
- {
- if(!Input.empty())
- {
- Input.insert( At, Begin, End );
- }
- else
- {
- Input.insert( Input.begin(), Begin, End );
- }
- }
- }
- };
-
- template< bool HasNative >
- struct replace_native_helper
- {
- template< typename InputT, typename ForwardIteratorT >
- void operator()(
- InputT& Input,
- BOOST_STRING_TYPENAME InputT::iterator From,
- BOOST_STRING_TYPENAME InputT::iterator To,
- ForwardIteratorT Begin,
- ForwardIteratorT End )
- {
- replace_const_time_helper<
- boost::mpl::and_<
- has_const_time_insert<InputT>,
- has_const_time_erase<InputT> >::value >()(
- Input, From, To, Begin, End );
- }
- };
-
- template<>
- struct replace_native_helper< true >
- {
- template< typename InputT, typename ForwardIteratorT >
- void operator()(
- InputT& Input,
- BOOST_STRING_TYPENAME InputT::iterator From,
- BOOST_STRING_TYPENAME InputT::iterator To,
- ForwardIteratorT Begin,
- ForwardIteratorT End )
- {
- Input.replace( From, To, Begin, End );
- }
- };
-
- template< typename InputT, typename ForwardIteratorT >
- inline void replace(
- InputT& Input,
- BOOST_STRING_TYPENAME InputT::iterator From,
- BOOST_STRING_TYPENAME InputT::iterator To,
- ForwardIteratorT Begin,
- ForwardIteratorT End )
- {
- replace_native_helper< has_native_replace<InputT>::value >()(
- Input, From, To, Begin, End );
- }
- template< typename InputT, typename InsertT >
- inline void replace(
- InputT& Input,
- BOOST_STRING_TYPENAME InputT::iterator From,
- BOOST_STRING_TYPENAME InputT::iterator To,
- const InsertT& Insert )
- {
- if(From!=To)
- {
- replace( Input, From, To, ::boost::begin(Insert), ::boost::end(Insert) );
- }
- else
- {
- insert( Input, From, ::boost::begin(Insert), ::boost::end(Insert) );
- }
- }
- }
- }
- }
- #endif
|