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