123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #ifndef BOOST_STRING_REPLACE_STORAGE_DETAIL_HPP
- #define BOOST_STRING_REPLACE_STORAGE_DETAIL_HPP
- #include <boost/algorithm/string/config.hpp>
- #include <algorithm>
- #include <boost/mpl/bool.hpp>
- #include <boost/algorithm/string/sequence_traits.hpp>
- #include <boost/algorithm/string/detail/sequence.hpp>
- namespace boost {
- namespace algorithm {
- namespace detail {
-
- template< typename StorageT, typename OutputIteratorT >
- inline OutputIteratorT move_from_storage(
- StorageT& Storage,
- OutputIteratorT DestBegin,
- OutputIteratorT DestEnd )
- {
- OutputIteratorT OutputIt=DestBegin;
-
- while( !Storage.empty() && OutputIt!=DestEnd )
- {
- *OutputIt=Storage.front();
- Storage.pop_front();
- ++OutputIt;
- }
- return OutputIt;
- }
- template< typename StorageT, typename WhatT >
- inline void copy_to_storage(
- StorageT& Storage,
- const WhatT& What )
- {
- Storage.insert( Storage.end(), ::boost::begin(What), ::boost::end(What) );
- }
- template< bool HasStableIterators >
- struct process_segment_helper
- {
-
- template<
- typename StorageT,
- typename InputT,
- typename ForwardIteratorT >
- ForwardIteratorT operator()(
- StorageT& Storage,
- InputT& ,
- ForwardIteratorT InsertIt,
- ForwardIteratorT SegmentBegin,
- ForwardIteratorT SegmentEnd )
- {
-
- ForwardIteratorT It=move_from_storage( Storage, InsertIt, SegmentBegin );
-
-
-
-
- if( Storage.empty() )
- {
- if( It==SegmentBegin )
- {
-
- return SegmentEnd;
- }
- else
- {
-
- return std::copy( SegmentBegin, SegmentEnd, It );
- }
- }
- else
- {
-
- while( It!=SegmentEnd )
- {
-
- Storage.push_back( *It );
-
- *It=Storage.front();
- Storage.pop_front();
-
- ++It;
- }
- return It;
- }
- }
- };
- template<>
- struct process_segment_helper< true >
- {
-
- template<
- typename StorageT,
- typename InputT,
- typename ForwardIteratorT >
- ForwardIteratorT operator()(
- StorageT& Storage,
- InputT& Input,
- ForwardIteratorT InsertIt,
- ForwardIteratorT SegmentBegin,
- ForwardIteratorT SegmentEnd )
- {
-
- replace( Input, InsertIt, SegmentBegin, Storage );
-
- Storage.clear();
-
- return SegmentEnd;
- }
- };
-
- template<
- typename StorageT,
- typename InputT,
- typename ForwardIteratorT >
- inline ForwardIteratorT process_segment(
- StorageT& Storage,
- InputT& Input,
- ForwardIteratorT InsertIt,
- ForwardIteratorT SegmentBegin,
- ForwardIteratorT SegmentEnd )
- {
- return
- process_segment_helper<
- has_stable_iterators<InputT>::value>()(
- Storage, Input, InsertIt, SegmentBegin, SegmentEnd );
- }
-
- }
- }
- }
- #endif
|