source: NonGTP/Boost/boost/algorithm/string/detail/trim.hpp @ 857

Revision 857, 3.2 KB checked in by igarcia, 18 years ago (diff)
Line 
1//  Boost string_algo library trim.hpp header file  ---------------------------//
2
3//  Copyright Pavol Droba 2002-2003. Use, modification and
4//  distribution is subject to the Boost Software License, Version
5//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
6//  http://www.boost.org/LICENSE_1_0.txt)
7
8//  See http://www.boost.org for updates, documentation, and revision history.
9
10#ifndef BOOST_STRING_TRIM_DETAIL_HPP
11#define BOOST_STRING_TRIM_DETAIL_HPP
12
13#include <boost/algorithm/string/config.hpp>
14#include <boost/detail/iterator.hpp>
15
16namespace boost {
17    namespace algorithm {
18        namespace detail {
19
20//  trim iterator helper -----------------------------------------------//
21
22            // Search for first non matching character from the beginning of the sequence
23            template< typename ForwardIteratorT, typename PredicateT >
24            inline ForwardIteratorT trim_begin(
25                ForwardIteratorT InBegin,
26                ForwardIteratorT InEnd,
27                PredicateT IsSpace )
28            {
29                ForwardIteratorT It=InBegin;
30                for(; It!=InEnd; ++It )
31                {
32                    if (!IsSpace(*It))
33                        return It;
34                }
35
36                return It;
37            }
38
39            // Search for first non matching character from the end of the sequence
40            template< typename ForwardIteratorT, typename PredicateT >
41            inline ForwardIteratorT trim_end(
42                ForwardIteratorT InBegin,
43                ForwardIteratorT InEnd,
44                PredicateT IsSpace )
45            {
46                typedef BOOST_STRING_TYPENAME boost::detail::
47                    iterator_traits<ForwardIteratorT>::iterator_category category;
48
49                return trim_end_iter_select( InBegin, InEnd, IsSpace, category() );
50            }
51
52            template< typename ForwardIteratorT, typename PredicateT >
53            inline ForwardIteratorT trim_end_iter_select(
54                ForwardIteratorT InBegin,
55                ForwardIteratorT InEnd,
56                PredicateT IsSpace,
57                std::forward_iterator_tag )
58            {
59                ForwardIteratorT TrimIt=InBegin;
60
61                for( ForwardIteratorT It=InBegin; It!=InEnd; ++It )
62                {
63                    if ( !IsSpace(*It) )
64                    {
65                        TrimIt=It;
66                        ++TrimIt;
67                    }
68                }
69
70                return TrimIt;
71            }
72
73            template< typename ForwardIteratorT, typename PredicateT >
74            inline ForwardIteratorT trim_end_iter_select(
75                ForwardIteratorT InBegin,
76                ForwardIteratorT InEnd,
77                PredicateT IsSpace,
78                std::bidirectional_iterator_tag )
79            {
80                for( ForwardIteratorT It=InEnd; It!=InBegin;  )
81                {
82                    if ( !IsSpace(*(--It)) )
83                        return ++It;
84                }
85
86                return InBegin;
87            }
88
89        } // namespace detail
90    } // namespace algorithm
91} // namespace boost
92
93
94#endif  // BOOST_STRING_TRIM_DETAIL_HPP
Note: See TracBrowser for help on using the repository browser.