]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost string_algo library string_funct.hpp header file ---------------------------// |
2 | ||
3 | // Copyright Pavol Droba 2002-2003. | |
4 | // | |
5 | // Distributed under the Boost Software License, Version 1.0. | |
6 | // (See accompanying file LICENSE_1_0.txt or copy at | |
7 | // http://www.boost.org/LICENSE_1_0.txt) | |
8 | ||
9 | // See http://www.boost.org/ for updates, documentation, and revision history. | |
10 | ||
11 | #ifndef BOOST_STRING_CASE_CONV_DETAIL_HPP | |
12 | #define BOOST_STRING_CASE_CONV_DETAIL_HPP | |
13 | ||
14 | #include <boost/algorithm/string/config.hpp> | |
15 | #include <locale> | |
16 | #include <functional> | |
17 | ||
18 | #include <boost/type_traits/make_unsigned.hpp> | |
19 | ||
20 | namespace boost { | |
21 | namespace algorithm { | |
22 | namespace detail { | |
23 | ||
24 | // case conversion functors -----------------------------------------------// | |
25 | ||
26 | #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) | |
27 | #pragma warning(push) | |
28 | #pragma warning(disable:4512) //assignment operator could not be generated | |
29 | #endif | |
30 | ||
31 | // a tolower functor | |
32 | template<typename CharT> | |
33 | struct to_lowerF : public std::unary_function<CharT, CharT> | |
34 | { | |
35 | // Constructor | |
36 | to_lowerF( const std::locale& Loc ) : m_Loc( &Loc ) {} | |
37 | ||
38 | // Operation | |
39 | CharT operator ()( CharT Ch ) const | |
40 | { | |
41 | #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) | |
42 | return std::tolower( static_cast<typename boost::make_unsigned <CharT>::type> ( Ch )); | |
43 | #else | |
44 | return std::tolower<CharT>( Ch, *m_Loc ); | |
45 | #endif | |
46 | } | |
47 | private: | |
48 | const std::locale* m_Loc; | |
49 | }; | |
50 | ||
51 | // a toupper functor | |
52 | template<typename CharT> | |
53 | struct to_upperF : public std::unary_function<CharT, CharT> | |
54 | { | |
55 | // Constructor | |
56 | to_upperF( const std::locale& Loc ) : m_Loc( &Loc ) {} | |
57 | ||
58 | // Operation | |
59 | CharT operator ()( CharT Ch ) const | |
60 | { | |
61 | #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL) | |
62 | return std::toupper( static_cast<typename boost::make_unsigned <CharT>::type> ( Ch )); | |
63 | #else | |
64 | return std::toupper<CharT>( Ch, *m_Loc ); | |
65 | #endif | |
66 | } | |
67 | private: | |
68 | const std::locale* m_Loc; | |
69 | }; | |
70 | ||
71 | #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) | |
72 | #pragma warning(pop) | |
73 | #endif | |
74 | ||
75 | // algorithm implementation ------------------------------------------------------------------------- | |
76 | ||
77 | // Transform a range | |
78 | template<typename OutputIteratorT, typename RangeT, typename FunctorT> | |
79 | OutputIteratorT transform_range_copy( | |
80 | OutputIteratorT Output, | |
81 | const RangeT& Input, | |
82 | FunctorT Functor) | |
83 | { | |
84 | return std::transform( | |
85 | ::boost::begin(Input), | |
86 | ::boost::end(Input), | |
87 | Output, | |
88 | Functor); | |
89 | } | |
90 | ||
91 | // Transform a range (in-place) | |
92 | template<typename RangeT, typename FunctorT> | |
93 | void transform_range( | |
94 | const RangeT& Input, | |
95 | FunctorT Functor) | |
96 | { | |
97 | std::transform( | |
98 | ::boost::begin(Input), | |
99 | ::boost::end(Input), | |
100 | ::boost::begin(Input), | |
101 | Functor); | |
102 | } | |
103 | ||
104 | template<typename SequenceT, typename RangeT, typename FunctorT> | |
105 | inline SequenceT transform_range_copy( | |
106 | const RangeT& Input, | |
107 | FunctorT Functor) | |
108 | { | |
109 | return SequenceT( | |
110 | ::boost::make_transform_iterator( | |
111 | ::boost::begin(Input), | |
112 | Functor), | |
113 | ::boost::make_transform_iterator( | |
114 | ::boost::end(Input), | |
115 | Functor)); | |
116 | } | |
117 | ||
118 | } // namespace detail | |
119 | } // namespace algorithm | |
120 | } // namespace boost | |
121 | ||
122 | ||
123 | #endif // BOOST_STRING_CASE_CONV_DETAIL_HPP |