Include bind in ndnboost.
diff --git a/ndnboost/algorithm/string/detail/find_format.hpp b/ndnboost/algorithm/string/detail/find_format.hpp
new file mode 100644
index 0000000..395beaf
--- /dev/null
+++ b/ndnboost/algorithm/string/detail/find_format.hpp
@@ -0,0 +1,204 @@
+// Boost string_algo library find_format.hpp header file ---------------------------//
+
+// Copyright Pavol Droba 2002-2003.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/ for updates, documentation, and revision history.
+
+#ifndef BOOST_STRING_FIND_FORMAT_DETAIL_HPP
+#define BOOST_STRING_FIND_FORMAT_DETAIL_HPP
+
+#include <ndnboost/algorithm/string/config.hpp>
+#include <ndnboost/range/iterator_range.hpp>
+#include <ndnboost/range/const_iterator.hpp>
+#include <ndnboost/range/iterator.hpp>
+#include <ndnboost/algorithm/string/detail/find_format_store.hpp>
+#include <ndnboost/algorithm/string/detail/replace_storage.hpp>
+
+namespace ndnboost {
+ namespace algorithm {
+ namespace detail {
+
+// find_format_copy (iterator variant) implementation -------------------------------//
+
+ template<
+ typename OutputIteratorT,
+ typename InputT,
+ typename FormatterT,
+ typename FindResultT,
+ typename FormatResultT >
+ inline OutputIteratorT find_format_copy_impl2(
+ OutputIteratorT Output,
+ const InputT& Input,
+ FormatterT Formatter,
+ const FindResultT& FindResult,
+ const FormatResultT& FormatResult )
+ {
+ typedef find_format_store<
+ BOOST_STRING_TYPENAME
+ range_const_iterator<InputT>::type,
+ FormatterT,
+ FormatResultT > store_type;
+
+ // Create store for the find result
+ store_type M( FindResult, FormatResult, Formatter );
+
+ if ( !M )
+ {
+ // Match not found - return original sequence
+ Output = std::copy( ::ndnboost::begin(Input), ::ndnboost::end(Input), Output );
+ return Output;
+ }
+
+ // Copy the beginning of the sequence
+ Output = std::copy( ::ndnboost::begin(Input), ::ndnboost::begin(M), Output );
+ // Format find result
+ // Copy formatted result
+ Output = std::copy( ::ndnboost::begin(M.format_result()), ::ndnboost::end(M.format_result()), Output );
+ // Copy the rest of the sequence
+ Output = std::copy( M.end(), ::ndnboost::end(Input), Output );
+
+ return Output;
+ }
+
+ template<
+ typename OutputIteratorT,
+ typename InputT,
+ typename FormatterT,
+ typename FindResultT >
+ inline OutputIteratorT find_format_copy_impl(
+ OutputIteratorT Output,
+ const InputT& Input,
+ FormatterT Formatter,
+ const FindResultT& FindResult )
+ {
+ if( ::ndnboost::algorithm::detail::check_find_result(Input, FindResult) ) {
+ return ::ndnboost::algorithm::detail::find_format_copy_impl2(
+ Output,
+ Input,
+ Formatter,
+ FindResult,
+ Formatter(FindResult) );
+ } else {
+ return std::copy( ::ndnboost::begin(Input), ::ndnboost::end(Input), Output );
+ }
+ }
+
+
+// find_format_copy implementation --------------------------------------------------//
+
+ template<
+ typename InputT,
+ typename FormatterT,
+ typename FindResultT,
+ typename FormatResultT >
+ inline InputT find_format_copy_impl2(
+ const InputT& Input,
+ FormatterT Formatter,
+ const FindResultT& FindResult,
+ const FormatResultT& FormatResult)
+ {
+ typedef find_format_store<
+ BOOST_STRING_TYPENAME
+ range_const_iterator<InputT>::type,
+ FormatterT,
+ FormatResultT > store_type;
+
+ // Create store for the find result
+ store_type M( FindResult, FormatResult, Formatter );
+
+ if ( !M )
+ {
+ // Match not found - return original sequence
+ return InputT( Input );
+ }
+
+ InputT Output;
+ // Copy the beginning of the sequence
+ ndnboost::algorithm::detail::insert( Output, ::ndnboost::end(Output), ::ndnboost::begin(Input), M.begin() );
+ // Copy formatted result
+ ndnboost::algorithm::detail::insert( Output, ::ndnboost::end(Output), M.format_result() );
+ // Copy the rest of the sequence
+ ndnboost::algorithm::detail::insert( Output, ::ndnboost::end(Output), M.end(), ::ndnboost::end(Input) );
+
+ return Output;
+ }
+
+ template<
+ typename InputT,
+ typename FormatterT,
+ typename FindResultT >
+ inline InputT find_format_copy_impl(
+ const InputT& Input,
+ FormatterT Formatter,
+ const FindResultT& FindResult)
+ {
+ if( ::ndnboost::algorithm::detail::check_find_result(Input, FindResult) ) {
+ return ::ndnboost::algorithm::detail::find_format_copy_impl2(
+ Input,
+ Formatter,
+ FindResult,
+ Formatter(FindResult) );
+ } else {
+ return Input;
+ }
+ }
+
+ // replace implementation ----------------------------------------------------//
+
+ template<
+ typename InputT,
+ typename FormatterT,
+ typename FindResultT,
+ typename FormatResultT >
+ inline void find_format_impl2(
+ InputT& Input,
+ FormatterT Formatter,
+ const FindResultT& FindResult,
+ const FormatResultT& FormatResult)
+ {
+ typedef find_format_store<
+ BOOST_STRING_TYPENAME
+ range_iterator<InputT>::type,
+ FormatterT,
+ FormatResultT > store_type;
+
+ // Create store for the find result
+ store_type M( FindResult, FormatResult, Formatter );
+
+ if ( !M )
+ {
+ // Search not found - return original sequence
+ return;
+ }
+
+ // Replace match
+ ::ndnboost::algorithm::detail::replace( Input, M.begin(), M.end(), M.format_result() );
+ }
+
+ template<
+ typename InputT,
+ typename FormatterT,
+ typename FindResultT >
+ inline void find_format_impl(
+ InputT& Input,
+ FormatterT Formatter,
+ const FindResultT& FindResult)
+ {
+ if( ::ndnboost::algorithm::detail::check_find_result(Input, FindResult) ) {
+ ::ndnboost::algorithm::detail::find_format_impl2(
+ Input,
+ Formatter,
+ FindResult,
+ Formatter(FindResult) );
+ }
+ }
+
+ } // namespace detail
+ } // namespace algorithm
+} // namespace ndnboost
+
+#endif // BOOST_STRING_FIND_FORMAT_DETAIL_HPP
diff --git a/ndnboost/algorithm/string/detail/find_format_all.hpp b/ndnboost/algorithm/string/detail/find_format_all.hpp
new file mode 100644
index 0000000..ee0312a
--- /dev/null
+++ b/ndnboost/algorithm/string/detail/find_format_all.hpp
@@ -0,0 +1,273 @@
+// Boost string_algo library find_format_all.hpp header file ---------------------------//
+
+// Copyright Pavol Droba 2002-2003.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/ for updates, documentation, and revision history.
+
+#ifndef BOOST_STRING_FIND_FORMAT_ALL_DETAIL_HPP
+#define BOOST_STRING_FIND_FORMAT_ALL_DETAIL_HPP
+
+#include <ndnboost/algorithm/string/config.hpp>
+#include <ndnboost/range/iterator_range.hpp>
+#include <ndnboost/range/const_iterator.hpp>
+#include <ndnboost/range/value_type.hpp>
+#include <ndnboost/algorithm/string/detail/find_format_store.hpp>
+#include <ndnboost/algorithm/string/detail/replace_storage.hpp>
+
+namespace ndnboost {
+ namespace algorithm {
+ namespace detail {
+
+// find_format_all_copy (iterator variant) implementation ---------------------------//
+
+ template<
+ typename OutputIteratorT,
+ typename InputT,
+ typename FinderT,
+ typename FormatterT,
+ typename FindResultT,
+ typename FormatResultT >
+ inline OutputIteratorT find_format_all_copy_impl2(
+ OutputIteratorT Output,
+ const InputT& Input,
+ FinderT Finder,
+ FormatterT Formatter,
+ const FindResultT& FindResult,
+ const FormatResultT& FormatResult )
+ {
+ typedef BOOST_STRING_TYPENAME
+ range_const_iterator<InputT>::type input_iterator_type;
+
+ typedef find_format_store<
+ input_iterator_type,
+ FormatterT,
+ FormatResultT > store_type;
+
+ // Create store for the find result
+ store_type M( FindResult, FormatResult, Formatter );
+
+ // Initialize last match
+ input_iterator_type LastMatch=::ndnboost::begin(Input);
+
+ // Iterate through all matches
+ while( M )
+ {
+ // Copy the beginning of the sequence
+ Output = std::copy( LastMatch, M.begin(), Output );
+ // Copy formatted result
+ Output = std::copy( ::ndnboost::begin(M.format_result()), ::ndnboost::end(M.format_result()), Output );
+
+ // Proceed to the next match
+ LastMatch=M.end();
+ M=Finder( LastMatch, ::ndnboost::end(Input) );
+ }
+
+ // Copy the rest of the sequence
+ Output = std::copy( LastMatch, ::ndnboost::end(Input), Output );
+
+ return Output;
+ }
+
+ template<
+ typename OutputIteratorT,
+ typename InputT,
+ typename FinderT,
+ typename FormatterT,
+ typename FindResultT >
+ inline OutputIteratorT find_format_all_copy_impl(
+ OutputIteratorT Output,
+ const InputT& Input,
+ FinderT Finder,
+ FormatterT Formatter,
+ const FindResultT& FindResult )
+ {
+ if( ::ndnboost::algorithm::detail::check_find_result(Input, FindResult) ) {
+ return ::ndnboost::algorithm::detail::find_format_all_copy_impl2(
+ Output,
+ Input,
+ Finder,
+ Formatter,
+ FindResult,
+ Formatter(FindResult) );
+ } else {
+ return std::copy( ::ndnboost::begin(Input), ::ndnboost::end(Input), Output );
+ }
+ }
+
+ // find_format_all_copy implementation ----------------------------------------------//
+
+ template<
+ typename InputT,
+ typename FinderT,
+ typename FormatterT,
+ typename FindResultT,
+ typename FormatResultT >
+ inline InputT find_format_all_copy_impl2(
+ const InputT& Input,
+ FinderT Finder,
+ FormatterT Formatter,
+ const FindResultT& FindResult,
+ const FormatResultT& FormatResult)
+ {
+ typedef BOOST_STRING_TYPENAME
+ range_const_iterator<InputT>::type input_iterator_type;
+
+ typedef find_format_store<
+ input_iterator_type,
+ FormatterT,
+ FormatResultT > store_type;
+
+ // Create store for the find result
+ store_type M( FindResult, FormatResult, Formatter );
+
+ // Initialize last match
+ input_iterator_type LastMatch=::ndnboost::begin(Input);
+
+ // Output temporary
+ InputT Output;
+
+ // Iterate through all matches
+ while( M )
+ {
+ // Copy the beginning of the sequence
+ ndnboost::algorithm::detail::insert( Output, ::ndnboost::end(Output), LastMatch, M.begin() );
+ // Copy formatted result
+ ndnboost::algorithm::detail::insert( Output, ::ndnboost::end(Output), M.format_result() );
+
+ // Proceed to the next match
+ LastMatch=M.end();
+ M=Finder( LastMatch, ::ndnboost::end(Input) );
+ }
+
+ // Copy the rest of the sequence
+ ::ndnboost::algorithm::detail::insert( Output, ::ndnboost::end(Output), LastMatch, ::ndnboost::end(Input) );
+
+ return Output;
+ }
+
+ template<
+ typename InputT,
+ typename FinderT,
+ typename FormatterT,
+ typename FindResultT >
+ inline InputT find_format_all_copy_impl(
+ const InputT& Input,
+ FinderT Finder,
+ FormatterT Formatter,
+ const FindResultT& FindResult)
+ {
+ if( ::ndnboost::algorithm::detail::check_find_result(Input, FindResult) ) {
+ return ::ndnboost::algorithm::detail::find_format_all_copy_impl2(
+ Input,
+ Finder,
+ Formatter,
+ FindResult,
+ Formatter(FindResult) );
+ } else {
+ return Input;
+ }
+ }
+
+ // find_format_all implementation ------------------------------------------------//
+
+ template<
+ typename InputT,
+ typename FinderT,
+ typename FormatterT,
+ typename FindResultT,
+ typename FormatResultT >
+ inline void find_format_all_impl2(
+ InputT& Input,
+ FinderT Finder,
+ FormatterT Formatter,
+ FindResultT FindResult,
+ FormatResultT FormatResult)
+ {
+ typedef BOOST_STRING_TYPENAME
+ range_iterator<InputT>::type input_iterator_type;
+ typedef find_format_store<
+ input_iterator_type,
+ FormatterT,
+ FormatResultT > store_type;
+
+ // Create store for the find result
+ store_type M( FindResult, FormatResult, Formatter );
+
+ // Instantiate replacement storage
+ std::deque<
+ BOOST_STRING_TYPENAME range_value<InputT>::type> Storage;
+
+ // Initialize replacement iterators
+ input_iterator_type InsertIt=::ndnboost::begin(Input);
+ input_iterator_type SearchIt=::ndnboost::begin(Input);
+
+ while( M )
+ {
+ // process the segment
+ InsertIt=process_segment(
+ Storage,
+ Input,
+ InsertIt,
+ SearchIt,
+ M.begin() );
+
+ // Adjust search iterator
+ SearchIt=M.end();
+
+ // Copy formatted replace to the storage
+ ::ndnboost::algorithm::detail::copy_to_storage( Storage, M.format_result() );
+
+ // Find range for a next match
+ M=Finder( SearchIt, ::ndnboost::end(Input) );
+ }
+
+ // process the last segment
+ InsertIt=::ndnboost::algorithm::detail::process_segment(
+ Storage,
+ Input,
+ InsertIt,
+ SearchIt,
+ ::ndnboost::end(Input) );
+
+ if ( Storage.empty() )
+ {
+ // Truncate input
+ ::ndnboost::algorithm::detail::erase( Input, InsertIt, ::ndnboost::end(Input) );
+ }
+ else
+ {
+ // Copy remaining data to the end of input
+ ::ndnboost::algorithm::detail::insert( Input, ::ndnboost::end(Input), Storage.begin(), Storage.end() );
+ }
+ }
+
+ template<
+ typename InputT,
+ typename FinderT,
+ typename FormatterT,
+ typename FindResultT >
+ inline void find_format_all_impl(
+ InputT& Input,
+ FinderT Finder,
+ FormatterT Formatter,
+ FindResultT FindResult)
+ {
+ if( ::ndnboost::algorithm::detail::check_find_result(Input, FindResult) ) {
+ ::ndnboost::algorithm::detail::find_format_all_impl2(
+ Input,
+ Finder,
+ Formatter,
+ FindResult,
+ Formatter(FindResult) );
+ }
+ }
+
+ } // namespace detail
+ } // namespace algorithm
+} // namespace ndnboost
+
+#endif // BOOST_STRING_FIND_FORMAT_ALL_DETAIL_HPP
diff --git a/ndnboost/algorithm/string/detail/find_format_store.hpp b/ndnboost/algorithm/string/detail/find_format_store.hpp
new file mode 100644
index 0000000..d0d38bf
--- /dev/null
+++ b/ndnboost/algorithm/string/detail/find_format_store.hpp
@@ -0,0 +1,89 @@
+// Boost string_algo library find_format_store.hpp header file ---------------------------//
+
+// Copyright Pavol Droba 2002-2003.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/ for updates, documentation, and revision history.
+
+#ifndef BOOST_STRING_FIND_FORMAT_STORE_DETAIL_HPP
+#define BOOST_STRING_FIND_FORMAT_STORE_DETAIL_HPP
+
+#include <ndnboost/algorithm/string/config.hpp>
+#include <ndnboost/range/iterator_range.hpp>
+
+namespace ndnboost {
+ namespace algorithm {
+ namespace detail {
+
+// temporary format and find result storage --------------------------------//
+
+#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
+#pragma warning(push)
+#pragma warning(disable:4512) //assignment operator could not be generated
+#endif
+ template<
+ typename ForwardIteratorT,
+ typename FormatterT,
+ typename FormatResultT >
+ class find_format_store :
+ public iterator_range<ForwardIteratorT>
+ {
+ public:
+ // typedefs
+ typedef iterator_range<ForwardIteratorT> base_type;
+ typedef FormatterT formatter_type;
+ typedef FormatResultT format_result_type;
+
+ public:
+ // Construction
+ find_format_store(
+ const base_type& FindResult,
+ const format_result_type& FormatResult,
+ const formatter_type& Formatter ) :
+ base_type(FindResult),
+ m_FormatResult(FormatResult),
+ m_Formatter(Formatter) {}
+
+ // Assignment
+ template< typename FindResultT >
+ find_format_store& operator=( FindResultT FindResult )
+ {
+ iterator_range<ForwardIteratorT>::operator=(FindResult);
+ if( !this->empty() ) {
+ m_FormatResult=m_Formatter(FindResult);
+ }
+
+ return *this;
+ }
+
+ // Retrieve format result
+ const format_result_type& format_result()
+ {
+ return m_FormatResult;
+ }
+
+ private:
+ format_result_type m_FormatResult;
+ const formatter_type& m_Formatter;
+ };
+
+ template<typename InputT, typename FindResultT>
+ bool check_find_result(InputT&, FindResultT& FindResult)
+ {
+ typedef BOOST_STRING_TYPENAME
+ range_const_iterator<InputT>::type input_iterator_type;
+ iterator_range<input_iterator_type> ResultRange(FindResult);
+ return !ResultRange.empty();
+ }
+
+#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
+#pragma warning(pop)
+#endif
+ } // namespace detail
+ } // namespace algorithm
+} // namespace ndnboost
+
+#endif // BOOST_STRING_FIND_FORMAT_STORE_DETAIL_HPP
diff --git a/ndnboost/algorithm/string/detail/finder.hpp b/ndnboost/algorithm/string/detail/finder.hpp
new file mode 100644
index 0000000..330c7a5
--- /dev/null
+++ b/ndnboost/algorithm/string/detail/finder.hpp
@@ -0,0 +1,646 @@
+// Boost string_algo library finder.hpp header file ---------------------------//
+
+// Copyright Pavol Droba 2002-2006.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/ for updates, documentation, and revision history.
+
+#ifndef BOOST_STRING_FINDER_DETAIL_HPP
+#define BOOST_STRING_FINDER_DETAIL_HPP
+
+#include <ndnboost/algorithm/string/config.hpp>
+#include <ndnboost/algorithm/string/constants.hpp>
+#include <ndnboost/detail/iterator.hpp>
+
+#include <ndnboost/range/iterator_range.hpp>
+#include <ndnboost/range/begin.hpp>
+#include <ndnboost/range/end.hpp>
+#include <ndnboost/range/empty.hpp>
+#include <ndnboost/range/as_literal.hpp>
+
+namespace ndnboost {
+ namespace algorithm {
+ namespace detail {
+
+
+// find first functor -----------------------------------------------//
+
+ // find a subsequence in the sequence ( functor )
+ /*
+ Returns a pair <begin,end> marking the subsequence in the sequence.
+ If the find fails, functor returns <End,End>
+ */
+ template<typename SearchIteratorT,typename PredicateT>
+ struct first_finderF
+ {
+ typedef SearchIteratorT search_iterator_type;
+
+ // Construction
+ template< typename SearchT >
+ first_finderF( const SearchT& Search, PredicateT Comp ) :
+ m_Search(::ndnboost::begin(Search), ::ndnboost::end(Search)), m_Comp(Comp) {}
+ first_finderF(
+ search_iterator_type SearchBegin,
+ search_iterator_type SearchEnd,
+ PredicateT Comp ) :
+ m_Search(SearchBegin, SearchEnd), m_Comp(Comp) {}
+
+ // Operation
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ operator()(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End ) const
+ {
+ typedef iterator_range<ForwardIteratorT> result_type;
+ typedef ForwardIteratorT input_iterator_type;
+
+ // Outer loop
+ for(input_iterator_type OuterIt=Begin;
+ OuterIt!=End;
+ ++OuterIt)
+ {
+ // Sanity check
+ if( ndnboost::empty(m_Search) )
+ return result_type( End, End );
+
+ input_iterator_type InnerIt=OuterIt;
+ search_iterator_type SubstrIt=m_Search.begin();
+ for(;
+ InnerIt!=End && SubstrIt!=m_Search.end();
+ ++InnerIt,++SubstrIt)
+ {
+ if( !( m_Comp(*InnerIt,*SubstrIt) ) )
+ break;
+ }
+
+ // Substring matching succeeded
+ if ( SubstrIt==m_Search.end() )
+ return result_type( OuterIt, InnerIt );
+ }
+
+ return result_type( End, End );
+ }
+
+ private:
+ iterator_range<search_iterator_type> m_Search;
+ PredicateT m_Comp;
+ };
+
+// find last functor -----------------------------------------------//
+
+ // find the last match a subsequence in the sequence ( functor )
+ /*
+ Returns a pair <begin,end> marking the subsequence in the sequence.
+ If the find fails, returns <End,End>
+ */
+ template<typename SearchIteratorT, typename PredicateT>
+ struct last_finderF
+ {
+ typedef SearchIteratorT search_iterator_type;
+ typedef first_finderF<
+ search_iterator_type,
+ PredicateT> first_finder_type;
+
+ // Construction
+ template< typename SearchT >
+ last_finderF( const SearchT& Search, PredicateT Comp ) :
+ m_Search(::ndnboost::begin(Search), ::ndnboost::end(Search)), m_Comp(Comp) {}
+ last_finderF(
+ search_iterator_type SearchBegin,
+ search_iterator_type SearchEnd,
+ PredicateT Comp ) :
+ m_Search(SearchBegin, SearchEnd), m_Comp(Comp) {}
+
+ // Operation
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ operator()(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End ) const
+ {
+ typedef iterator_range<ForwardIteratorT> result_type;
+
+ if( ndnboost::empty(m_Search) )
+ return result_type( End, End );
+
+ typedef BOOST_STRING_TYPENAME ndnboost::detail::
+ iterator_traits<ForwardIteratorT>::iterator_category category;
+
+ return findit( Begin, End, category() );
+ }
+
+ private:
+ // forward iterator
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ findit(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End,
+ std::forward_iterator_tag ) const
+ {
+ typedef ForwardIteratorT input_iterator_type;
+ typedef iterator_range<ForwardIteratorT> result_type;
+
+ first_finder_type first_finder(
+ m_Search.begin(), m_Search.end(), m_Comp );
+
+ result_type M=first_finder( Begin, End );
+ result_type Last=M;
+
+ while( M )
+ {
+ Last=M;
+ M=first_finder( ::ndnboost::end(M), End );
+ }
+
+ return Last;
+ }
+
+ // bidirectional iterator
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ findit(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End,
+ std::bidirectional_iterator_tag ) const
+ {
+ typedef iterator_range<ForwardIteratorT> result_type;
+ typedef ForwardIteratorT input_iterator_type;
+
+ // Outer loop
+ for(input_iterator_type OuterIt=End;
+ OuterIt!=Begin; )
+ {
+ input_iterator_type OuterIt2=--OuterIt;
+
+ input_iterator_type InnerIt=OuterIt2;
+ search_iterator_type SubstrIt=m_Search.begin();
+ for(;
+ InnerIt!=End && SubstrIt!=m_Search.end();
+ ++InnerIt,++SubstrIt)
+ {
+ if( !( m_Comp(*InnerIt,*SubstrIt) ) )
+ break;
+ }
+
+ // Substring matching succeeded
+ if( SubstrIt==m_Search.end() )
+ return result_type( OuterIt2, InnerIt );
+ }
+
+ return result_type( End, End );
+ }
+
+ private:
+ iterator_range<search_iterator_type> m_Search;
+ PredicateT m_Comp;
+ };
+
+// find n-th functor -----------------------------------------------//
+
+ // find the n-th match of a subsequence in the sequence ( functor )
+ /*
+ Returns a pair <begin,end> marking the subsequence in the sequence.
+ If the find fails, returns <End,End>
+ */
+ template<typename SearchIteratorT, typename PredicateT>
+ struct nth_finderF
+ {
+ typedef SearchIteratorT search_iterator_type;
+ typedef first_finderF<
+ search_iterator_type,
+ PredicateT> first_finder_type;
+ typedef last_finderF<
+ search_iterator_type,
+ PredicateT> last_finder_type;
+
+ // Construction
+ template< typename SearchT >
+ nth_finderF(
+ const SearchT& Search,
+ int Nth,
+ PredicateT Comp) :
+ m_Search(::ndnboost::begin(Search), ::ndnboost::end(Search)),
+ m_Nth(Nth),
+ m_Comp(Comp) {}
+ nth_finderF(
+ search_iterator_type SearchBegin,
+ search_iterator_type SearchEnd,
+ int Nth,
+ PredicateT Comp) :
+ m_Search(SearchBegin, SearchEnd),
+ m_Nth(Nth),
+ m_Comp(Comp) {}
+
+ // Operation
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ operator()(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End ) const
+ {
+ if(m_Nth>=0)
+ {
+ return find_forward(Begin, End, m_Nth);
+ }
+ else
+ {
+ return find_backward(Begin, End, -m_Nth);
+ }
+
+ }
+
+ private:
+ // Implementation helpers
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ find_forward(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End,
+ unsigned int N) const
+ {
+ typedef ForwardIteratorT input_iterator_type;
+ typedef iterator_range<ForwardIteratorT> result_type;
+
+ // Sanity check
+ if( ndnboost::empty(m_Search) )
+ return result_type( End, End );
+
+ // Instantiate find functor
+ first_finder_type first_finder(
+ m_Search.begin(), m_Search.end(), m_Comp );
+
+ result_type M( Begin, Begin );
+
+ for( unsigned int n=0; n<=N; ++n )
+ {
+ // find next match
+ M=first_finder( ::ndnboost::end(M), End );
+
+ if ( !M )
+ {
+ // Subsequence not found, return
+ return M;
+ }
+ }
+
+ return M;
+ }
+
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ find_backward(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End,
+ unsigned int N) const
+ {
+ typedef ForwardIteratorT input_iterator_type;
+ typedef iterator_range<ForwardIteratorT> result_type;
+
+ // Sanity check
+ if( ndnboost::empty(m_Search) )
+ return result_type( End, End );
+
+ // Instantiate find functor
+ last_finder_type last_finder(
+ m_Search.begin(), m_Search.end(), m_Comp );
+
+ result_type M( End, End );
+
+ for( unsigned int n=1; n<=N; ++n )
+ {
+ // find next match
+ M=last_finder( Begin, ::ndnboost::begin(M) );
+
+ if ( !M )
+ {
+ // Subsequence not found, return
+ return M;
+ }
+ }
+
+ return M;
+ }
+
+
+ private:
+ iterator_range<search_iterator_type> m_Search;
+ int m_Nth;
+ PredicateT m_Comp;
+ };
+
+// find head/tail implementation helpers ---------------------------//
+
+ template<typename ForwardIteratorT>
+ iterator_range<ForwardIteratorT>
+ find_head_impl(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End,
+ unsigned int N,
+ std::forward_iterator_tag )
+ {
+ typedef ForwardIteratorT input_iterator_type;
+ typedef iterator_range<ForwardIteratorT> result_type;
+
+ input_iterator_type It=Begin;
+ for(
+ unsigned int Index=0;
+ Index<N && It!=End; ++Index,++It ) {};
+
+ return result_type( Begin, It );
+ }
+
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ find_head_impl(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End,
+ unsigned int N,
+ std::random_access_iterator_tag )
+ {
+ typedef ForwardIteratorT input_iterator_type;
+ typedef iterator_range<ForwardIteratorT> result_type;
+
+ if ( (End<=Begin) || ( static_cast<unsigned int>(End-Begin) < N ) )
+ return result_type( Begin, End );
+
+ return result_type(Begin,Begin+N);
+ }
+
+ // Find head implementation
+ template<typename ForwardIteratorT>
+ iterator_range<ForwardIteratorT>
+ find_head_impl(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End,
+ unsigned int N )
+ {
+ typedef BOOST_STRING_TYPENAME ndnboost::detail::
+ iterator_traits<ForwardIteratorT>::iterator_category category;
+
+ return ::ndnboost::algorithm::detail::find_head_impl( Begin, End, N, category() );
+ }
+
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ find_tail_impl(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End,
+ unsigned int N,
+ std::forward_iterator_tag )
+ {
+ typedef ForwardIteratorT input_iterator_type;
+ typedef iterator_range<ForwardIteratorT> result_type;
+
+ unsigned int Index=0;
+ input_iterator_type It=Begin;
+ input_iterator_type It2=Begin;
+
+ // Advance It2 by N increments
+ for( Index=0; Index<N && It2!=End; ++Index,++It2 ) {};
+
+ // Advance It, It2 to the end
+ for(; It2!=End; ++It,++It2 ) {};
+
+ return result_type( It, It2 );
+ }
+
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ find_tail_impl(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End,
+ unsigned int N,
+ std::bidirectional_iterator_tag )
+ {
+ typedef ForwardIteratorT input_iterator_type;
+ typedef iterator_range<ForwardIteratorT> result_type;
+
+ input_iterator_type It=End;
+ for(
+ unsigned int Index=0;
+ Index<N && It!=Begin; ++Index,--It ) {};
+
+ return result_type( It, End );
+ }
+
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ find_tail_impl(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End,
+ unsigned int N,
+ std::random_access_iterator_tag )
+ {
+ typedef ForwardIteratorT input_iterator_type;
+ typedef iterator_range<ForwardIteratorT> result_type;
+
+ if ( (End<=Begin) || ( static_cast<unsigned int>(End-Begin) < N ) )
+ return result_type( Begin, End );
+
+ return result_type( End-N, End );
+ }
+
+ // Operation
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ find_tail_impl(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End,
+ unsigned int N )
+ {
+ typedef BOOST_STRING_TYPENAME ndnboost::detail::
+ iterator_traits<ForwardIteratorT>::iterator_category category;
+
+ return ::ndnboost::algorithm::detail::find_tail_impl( Begin, End, N, category() );
+ }
+
+
+
+// find head functor -----------------------------------------------//
+
+
+ // find a head in the sequence ( functor )
+ /*
+ This functor find a head of the specified range. For
+ a specified N, the head is a subsequence of N starting
+ elements of the range.
+ */
+ struct head_finderF
+ {
+ // Construction
+ head_finderF( int N ) : m_N(N) {}
+
+ // Operation
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ operator()(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End ) const
+ {
+ if(m_N>=0)
+ {
+ return ::ndnboost::algorithm::detail::find_head_impl( Begin, End, m_N );
+ }
+ else
+ {
+ iterator_range<ForwardIteratorT> Res=
+ ::ndnboost::algorithm::detail::find_tail_impl( Begin, End, -m_N );
+
+ return ::ndnboost::make_iterator_range(Begin, Res.begin());
+ }
+ }
+
+ private:
+ int m_N;
+ };
+
+// find tail functor -----------------------------------------------//
+
+
+ // find a tail in the sequence ( functor )
+ /*
+ This functor find a tail of the specified range. For
+ a specified N, the head is a subsequence of N starting
+ elements of the range.
+ */
+ struct tail_finderF
+ {
+ // Construction
+ tail_finderF( int N ) : m_N(N) {}
+
+ // Operation
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ operator()(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End ) const
+ {
+ if(m_N>=0)
+ {
+ return ::ndnboost::algorithm::detail::find_tail_impl( Begin, End, m_N );
+ }
+ else
+ {
+ iterator_range<ForwardIteratorT> Res=
+ ::ndnboost::algorithm::detail::find_head_impl( Begin, End, -m_N );
+
+ return ::ndnboost::make_iterator_range(Res.end(), End);
+ }
+ }
+
+ private:
+ int m_N;
+ };
+
+// find token functor -----------------------------------------------//
+
+ // find a token in a sequence ( functor )
+ /*
+ This find functor finds a token specified be a predicate
+ in a sequence. It is equivalent of std::find algorithm,
+ with an exception that it return range instead of a single
+ iterator.
+
+ If bCompress is set to true, adjacent matching tokens are
+ concatenated into one match.
+ */
+ template< typename PredicateT >
+ struct token_finderF
+ {
+ // Construction
+ token_finderF(
+ PredicateT Pred,
+ token_compress_mode_type eCompress=token_compress_off ) :
+ m_Pred(Pred), m_eCompress(eCompress) {}
+
+ // Operation
+ template< typename ForwardIteratorT >
+ iterator_range<ForwardIteratorT>
+ operator()(
+ ForwardIteratorT Begin,
+ ForwardIteratorT End ) const
+ {
+ typedef iterator_range<ForwardIteratorT> result_type;
+
+ ForwardIteratorT It=std::find_if( Begin, End, m_Pred );
+
+ if( It==End )
+ {
+ return result_type( End, End );
+ }
+ else
+ {
+ ForwardIteratorT It2=It;
+
+ if( m_eCompress==token_compress_on )
+ {
+ // Find first non-matching character
+ while( It2!=End && m_Pred(*It2) ) ++It2;
+ }
+ else
+ {
+ // Advance by one position
+ ++It2;
+ }
+
+ return result_type( It, It2 );
+ }
+ }
+
+ private:
+ PredicateT m_Pred;
+ token_compress_mode_type m_eCompress;
+ };
+
+// find range functor -----------------------------------------------//
+
+ // find a range in the sequence ( functor )
+ /*
+ This functor actually does not perform any find operation.
+ It always returns given iterator range as a result.
+ */
+ template<typename ForwardIterator1T>
+ struct range_finderF
+ {
+ typedef ForwardIterator1T input_iterator_type;
+ typedef iterator_range<input_iterator_type> result_type;
+
+ // Construction
+ range_finderF(
+ input_iterator_type Begin,
+ input_iterator_type End ) : m_Range(Begin, End) {}
+
+ range_finderF(const iterator_range<input_iterator_type>& Range) :
+ m_Range(Range) {}
+
+ // Operation
+ template< typename ForwardIterator2T >
+ iterator_range<ForwardIterator2T>
+ operator()(
+ ForwardIterator2T,
+ ForwardIterator2T ) const
+ {
+#if BOOST_WORKAROUND( __MWERKS__, <= 0x3003 )
+ return iterator_range<const ForwardIterator2T>(this->m_Range);
+#elif BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
+ return iterator_range<ForwardIterator2T>(m_Range.begin(), m_Range.end());
+#else
+ return m_Range;
+#endif
+ }
+
+ private:
+ iterator_range<input_iterator_type> m_Range;
+ };
+
+
+ } // namespace detail
+ } // namespace algorithm
+} // namespace ndnboost
+
+#endif // BOOST_STRING_FINDER_DETAIL_HPP
diff --git a/ndnboost/algorithm/string/detail/formatter.hpp b/ndnboost/algorithm/string/detail/formatter.hpp
new file mode 100644
index 0000000..0307310
--- /dev/null
+++ b/ndnboost/algorithm/string/detail/formatter.hpp
@@ -0,0 +1,119 @@
+// Boost string_algo library formatter.hpp header file ---------------------------//
+
+// Copyright Pavol Droba 2002-2003.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_STRING_FORMATTER_DETAIL_HPP
+#define BOOST_STRING_FORMATTER_DETAIL_HPP
+
+
+#include <ndnboost/range/iterator_range.hpp>
+#include <ndnboost/range/begin.hpp>
+#include <ndnboost/range/end.hpp>
+#include <ndnboost/range/const_iterator.hpp>
+
+#include <ndnboost/algorithm/string/detail/util.hpp>
+
+// generic replace functors -----------------------------------------------//
+
+namespace ndnboost {
+ namespace algorithm {
+ namespace detail {
+
+// const format functor ----------------------------------------------------//
+
+ // constant format functor
+ template<typename RangeT>
+ struct const_formatF
+ {
+ private:
+ typedef BOOST_STRING_TYPENAME
+ range_const_iterator<RangeT>::type format_iterator;
+ typedef iterator_range<format_iterator> result_type;
+
+ public:
+ // Construction
+ const_formatF(const RangeT& Format) :
+ m_Format(::ndnboost::begin(Format), ::ndnboost::end(Format)) {}
+
+ // Operation
+#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
+ template<typename Range2T>
+ result_type& operator()(const Range2T&)
+ {
+ return m_Format;
+ }
+#endif
+
+ template<typename Range2T>
+ const result_type& operator()(const Range2T&) const
+ {
+ return m_Format;
+ }
+
+ private:
+ result_type m_Format;
+ };
+
+// identity format functor ----------------------------------------------------//
+
+ // identity format functor
+ template<typename RangeT>
+ struct identity_formatF
+ {
+ // Operation
+ template< typename Range2T >
+ const RangeT& operator()(const Range2T& Replace) const
+ {
+ return RangeT(::ndnboost::begin(Replace), ::ndnboost::end(Replace));
+ }
+ };
+
+// empty format functor ( used by erase ) ------------------------------------//
+
+ // empty format functor
+ template< typename CharT >
+ struct empty_formatF
+ {
+ template< typename ReplaceT >
+ empty_container<CharT> operator()(const ReplaceT&) const
+ {
+ return empty_container<CharT>();
+ }
+ };
+
+// dissect format functor ----------------------------------------------------//
+
+ // dissect format functor
+ template<typename FinderT>
+ struct dissect_formatF
+ {
+ public:
+ // Construction
+ dissect_formatF(FinderT Finder) :
+ m_Finder(Finder) {}
+
+ // Operation
+ template<typename RangeT>
+ inline iterator_range<
+ BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type>
+ operator()(const RangeT& Replace) const
+ {
+ return m_Finder(::ndnboost::begin(Replace), ::ndnboost::end(Replace));
+ }
+
+ private:
+ FinderT m_Finder;
+ };
+
+
+ } // namespace detail
+ } // namespace algorithm
+} // namespace ndnboost
+
+#endif // BOOST_STRING_FORMATTER_DETAIL_HPP
diff --git a/ndnboost/algorithm/string/detail/replace_storage.hpp b/ndnboost/algorithm/string/detail/replace_storage.hpp
new file mode 100644
index 0000000..6fb6c54
--- /dev/null
+++ b/ndnboost/algorithm/string/detail/replace_storage.hpp
@@ -0,0 +1,159 @@
+// Boost string_algo library replace_storage.hpp header file ---------------------------//
+
+// Copyright Pavol Droba 2002-2003.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/ for updates, documentation, and revision history.
+
+#ifndef BOOST_STRING_REPLACE_STORAGE_DETAIL_HPP
+#define BOOST_STRING_REPLACE_STORAGE_DETAIL_HPP
+
+#include <ndnboost/algorithm/string/config.hpp>
+#include <algorithm>
+#include <ndnboost/mpl/bool.hpp>
+#include <ndnboost/algorithm/string/sequence_traits.hpp>
+#include <ndnboost/algorithm/string/detail/sequence.hpp>
+
+namespace ndnboost {
+ namespace algorithm {
+ namespace detail {
+
+// storage handling routines -----------------------------------------------//
+
+ 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(), ::ndnboost::begin(What), ::ndnboost::end(What) );
+ }
+
+
+// process segment routine -----------------------------------------------//
+
+ template< bool HasStableIterators >
+ struct process_segment_helper
+ {
+ // Optimized version of process_segment for generic sequence
+ template<
+ typename StorageT,
+ typename InputT,
+ typename ForwardIteratorT >
+ ForwardIteratorT operator()(
+ StorageT& Storage,
+ InputT& /*Input*/,
+ ForwardIteratorT InsertIt,
+ ForwardIteratorT SegmentBegin,
+ ForwardIteratorT SegmentEnd )
+ {
+ // Copy data from the storage until the beginning of the segment
+ ForwardIteratorT It=::ndnboost::algorithm::detail::move_from_storage( Storage, InsertIt, SegmentBegin );
+
+ // 3 cases are possible :
+ // a) Storage is empty, It==SegmentBegin
+ // b) Storage is empty, It!=SegmentBegin
+ // c) Storage is not empty
+
+ if( Storage.empty() )
+ {
+ if( It==SegmentBegin )
+ {
+ // Case a) everything is grand, just return end of segment
+ return SegmentEnd;
+ }
+ else
+ {
+ // Case b) move the segment backwards
+ return std::copy( SegmentBegin, SegmentEnd, It );
+ }
+ }
+ else
+ {
+ // Case c) -> shift the segment to the left and keep the overlap in the storage
+ while( It!=SegmentEnd )
+ {
+ // Store value into storage
+ Storage.push_back( *It );
+ // Get the top from the storage and put it here
+ *It=Storage.front();
+ Storage.pop_front();
+
+ // Advance
+ ++It;
+ }
+
+ return It;
+ }
+ }
+ };
+
+ template<>
+ struct process_segment_helper< true >
+ {
+ // Optimized version of process_segment for list-like sequence
+ template<
+ typename StorageT,
+ typename InputT,
+ typename ForwardIteratorT >
+ ForwardIteratorT operator()(
+ StorageT& Storage,
+ InputT& Input,
+ ForwardIteratorT InsertIt,
+ ForwardIteratorT SegmentBegin,
+ ForwardIteratorT SegmentEnd )
+
+ {
+ // Call replace to do the job
+ ::ndnboost::algorithm::detail::replace( Input, InsertIt, SegmentBegin, Storage );
+ // Empty the storage
+ Storage.clear();
+ // Iterators were not changed, simply return the end of segment
+ return SegmentEnd;
+ }
+ };
+
+ // Process one segment in the replace_all algorithm
+ 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 );
+ }
+
+
+ } // namespace detail
+ } // namespace algorithm
+} // namespace ndnboost
+
+#endif // BOOST_STRING_REPLACE_STORAGE_DETAIL_HPP
diff --git a/ndnboost/algorithm/string/detail/sequence.hpp b/ndnboost/algorithm/string/detail/sequence.hpp
new file mode 100644
index 0000000..0b39a8b
--- /dev/null
+++ b/ndnboost/algorithm/string/detail/sequence.hpp
@@ -0,0 +1,200 @@
+// Boost string_algo library sequence.hpp header file ---------------------------//
+
+// Copyright Pavol Droba 2002-2003.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/ for updates, documentation, and revision history.
+
+#ifndef BOOST_STRING_DETAIL_SEQUENCE_HPP
+#define BOOST_STRING_DETAIL_SEQUENCE_HPP
+
+#include <ndnboost/algorithm/string/config.hpp>
+#include <ndnboost/mpl/bool.hpp>
+#include <ndnboost/mpl/logical.hpp>
+#include <ndnboost/range/begin.hpp>
+#include <ndnboost/range/end.hpp>
+
+#include <ndnboost/algorithm/string/sequence_traits.hpp>
+
+namespace ndnboost {
+ namespace algorithm {
+ namespace detail {
+
+// insert helpers -------------------------------------------------//
+
+ 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 )
+ {
+ ::ndnboost::algorithm::detail::insert( Input, At, ::ndnboost::begin(Insert), ::ndnboost::end(Insert) );
+ }
+
+// erase helper ---------------------------------------------------//
+
+ // Erase a range in the sequence
+ /*
+ Returns the iterator pointing just after the erase subrange
+ */
+ 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 );
+ }
+
+// replace helper implementation ----------------------------------//
+
+ // Optimized version of replace for generic sequence containers
+ // Assumption: insert and erase are expensive
+ 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 )
+ {
+ // Copy data to the container ( as much as possible )
+ ForwardIteratorT InsertIt=Begin;
+ BOOST_STRING_TYPENAME InputT::iterator InputIt=From;
+ for(; InsertIt!=End && InputIt!=To; InsertIt++, InputIt++ )
+ {
+ *InputIt=*InsertIt;
+ }
+
+ if ( InsertIt!=End )
+ {
+ // Replace sequence is longer, insert it
+ Input.insert( InputIt, InsertIt, End );
+ }
+ else
+ {
+ if ( InputIt!=To )
+ {
+ // Replace sequence is shorter, erase the rest
+ Input.erase( InputIt, To );
+ }
+ }
+ }
+ };
+
+ template<>
+ struct replace_const_time_helper< true >
+ {
+ // Const-time erase and insert methods -> use them
+ 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 );
+ }
+ }
+ }
+ };
+
+ // No native replace method
+ 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<
+ ndnboost::mpl::and_<
+ has_const_time_insert<InputT>,
+ has_const_time_erase<InputT> >::value >()(
+ Input, From, To, Begin, End );
+ }
+ };
+
+ // Container has native replace method
+ 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 );
+ }
+ };
+
+// replace helper -------------------------------------------------//
+
+ 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)
+ {
+ ::ndnboost::algorithm::detail::replace( Input, From, To, ::ndnboost::begin(Insert), ::ndnboost::end(Insert) );
+ }
+ else
+ {
+ ::ndnboost::algorithm::detail::insert( Input, From, ::ndnboost::begin(Insert), ::ndnboost::end(Insert) );
+ }
+ }
+
+ } // namespace detail
+ } // namespace algorithm
+} // namespace ndnboost
+
+
+#endif // BOOST_STRING_DETAIL_SEQUENCE_HPP
diff --git a/ndnboost/algorithm/string/detail/util.hpp b/ndnboost/algorithm/string/detail/util.hpp
new file mode 100644
index 0000000..fa34548
--- /dev/null
+++ b/ndnboost/algorithm/string/detail/util.hpp
@@ -0,0 +1,106 @@
+// Boost string_algo library util.hpp header file ---------------------------//
+
+// Copyright Pavol Droba 2002-2003.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/ for updates, documentation, and revision history.
+
+#ifndef BOOST_STRING_UTIL_DETAIL_HPP
+#define BOOST_STRING_UTIL_DETAIL_HPP
+
+#include <ndnboost/algorithm/string/config.hpp>
+#include <functional>
+#include <ndnboost/range/iterator_range.hpp>
+
+namespace ndnboost {
+ namespace algorithm {
+ namespace detail {
+
+// empty container -----------------------------------------------//
+
+ // empty_container
+ /*
+ This class represents always empty container,
+ containing elements of type CharT.
+
+ It is supposed to be used in a const version only
+ */
+ template< typename CharT >
+ struct empty_container
+ {
+ typedef empty_container<CharT> type;
+ typedef CharT value_type;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+ typedef const value_type& reference;
+ typedef const value_type& const_reference;
+ typedef const value_type* iterator;
+ typedef const value_type* const_iterator;
+
+
+ // Operations
+ const_iterator begin() const
+ {
+ return reinterpret_cast<const_iterator>(0);
+ }
+
+ const_iterator end() const
+ {
+ return reinterpret_cast<const_iterator>(0);
+ }
+
+ bool empty() const
+ {
+ return false;
+ }
+
+ size_type size() const
+ {
+ return 0;
+ }
+ };
+
+// bounded copy algorithm -----------------------------------------------//
+
+ // Bounded version of the std::copy algorithm
+ template<typename InputIteratorT, typename OutputIteratorT>
+ inline OutputIteratorT bounded_copy(
+ InputIteratorT First,
+ InputIteratorT Last,
+ OutputIteratorT DestFirst,
+ OutputIteratorT DestLast )
+ {
+ InputIteratorT InputIt=First;
+ OutputIteratorT OutputIt=DestFirst;
+ for(; InputIt!=Last && OutputIt!=DestLast; InputIt++, OutputIt++ )
+ {
+ *OutputIt=*InputIt;
+ }
+
+ return OutputIt;
+ }
+
+// iterator range utilities -----------------------------------------//
+
+ // copy range functor
+ template<
+ typename SeqT,
+ typename IteratorT=BOOST_STRING_TYPENAME SeqT::const_iterator >
+ struct copy_iterator_rangeF :
+ public std::unary_function< iterator_range<IteratorT>, SeqT >
+ {
+ SeqT operator()( const iterator_range<IteratorT>& Range ) const
+ {
+ return copy_range<SeqT>(Range);
+ }
+ };
+
+ } // namespace detail
+ } // namespace algorithm
+} // namespace ndnboost
+
+
+#endif // BOOST_STRING_UTIL_DETAIL_HPP