Chris@16: // Boost string_algo library trim.hpp header file ---------------------------// Chris@16: Chris@16: // Copyright Pavol Droba 2002-2003. Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org/ for updates, documentation, and revision history. Chris@16: Chris@16: #ifndef BOOST_STRING_TRIM_DETAIL_HPP Chris@16: #define BOOST_STRING_TRIM_DETAIL_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace algorithm { Chris@16: namespace detail { Chris@16: Chris@16: // trim iterator helper -----------------------------------------------// Chris@16: Chris@16: template< typename ForwardIteratorT, typename PredicateT > Chris@16: inline ForwardIteratorT trim_end_iter_select( Chris@16: ForwardIteratorT InBegin, Chris@16: ForwardIteratorT InEnd, Chris@16: PredicateT IsSpace, Chris@16: std::forward_iterator_tag ) Chris@16: { Chris@16: ForwardIteratorT TrimIt=InBegin; Chris@16: Chris@16: for( ForwardIteratorT It=InBegin; It!=InEnd; ++It ) Chris@16: { Chris@16: if ( !IsSpace(*It) ) Chris@16: { Chris@16: TrimIt=It; Chris@16: ++TrimIt; Chris@16: } Chris@16: } Chris@16: Chris@16: return TrimIt; Chris@16: } Chris@16: Chris@16: template< typename ForwardIteratorT, typename PredicateT > Chris@16: inline ForwardIteratorT trim_end_iter_select( Chris@16: ForwardIteratorT InBegin, Chris@16: ForwardIteratorT InEnd, Chris@16: PredicateT IsSpace, Chris@16: std::bidirectional_iterator_tag ) Chris@16: { Chris@16: for( ForwardIteratorT It=InEnd; It!=InBegin; ) Chris@16: { Chris@16: if ( !IsSpace(*(--It)) ) Chris@16: return ++It; Chris@16: } Chris@16: Chris@16: return InBegin; Chris@16: } Chris@16: // Search for first non matching character from the beginning of the sequence Chris@16: template< typename ForwardIteratorT, typename PredicateT > Chris@16: inline ForwardIteratorT trim_begin( Chris@16: ForwardIteratorT InBegin, Chris@16: ForwardIteratorT InEnd, Chris@16: PredicateT IsSpace ) Chris@16: { Chris@16: ForwardIteratorT It=InBegin; Chris@16: for(; It!=InEnd; ++It ) Chris@16: { Chris@16: if (!IsSpace(*It)) Chris@16: return It; Chris@16: } Chris@16: Chris@16: return It; Chris@16: } Chris@16: Chris@16: // Search for first non matching character from the end of the sequence Chris@16: template< typename ForwardIteratorT, typename PredicateT > Chris@16: inline ForwardIteratorT trim_end( Chris@16: ForwardIteratorT InBegin, Chris@16: ForwardIteratorT InEnd, Chris@16: PredicateT IsSpace ) Chris@16: { Chris@16: typedef BOOST_STRING_TYPENAME boost::detail:: Chris@16: iterator_traits::iterator_category category; Chris@16: Chris@16: return ::boost::algorithm::detail::trim_end_iter_select( InBegin, InEnd, IsSpace, category() ); Chris@16: } Chris@16: Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace algorithm Chris@16: } // namespace boost Chris@16: Chris@16: Chris@16: #endif // BOOST_STRING_TRIM_DETAIL_HPP