• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
34             {
35                 typedef CharT argument_type;
36                 typedef CharT result_type;
37                 // Constructor
to_lowerFboost::algorithm::detail::to_lowerF38                 to_lowerF( const std::locale& Loc ) : m_Loc( &Loc ) {}
39 
40                 // Operation
operator ()boost::algorithm::detail::to_lowerF41                 CharT operator ()( CharT Ch ) const
42                 {
43                     #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
44                         return std::tolower( static_cast<typename boost::make_unsigned <CharT>::type> ( Ch ));
45                     #else
46                         return std::tolower<CharT>( Ch, *m_Loc );
47                     #endif
48                 }
49             private:
50                 const std::locale* m_Loc;
51             };
52 
53             // a toupper functor
54             template<typename CharT>
55             struct to_upperF
56             {
57                 typedef CharT argument_type;
58                 typedef CharT result_type;
59                 // Constructor
to_upperFboost::algorithm::detail::to_upperF60                 to_upperF( const std::locale& Loc ) : m_Loc( &Loc ) {}
61 
62                 // Operation
operator ()boost::algorithm::detail::to_upperF63                 CharT operator ()( CharT Ch ) const
64                 {
65                     #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
66                         return std::toupper( static_cast<typename boost::make_unsigned <CharT>::type> ( Ch ));
67                     #else
68                         return std::toupper<CharT>( Ch, *m_Loc );
69                     #endif
70                 }
71             private:
72                 const std::locale* m_Loc;
73             };
74 
75 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
76 #pragma warning(pop)
77 #endif
78 
79 // algorithm implementation -------------------------------------------------------------------------
80 
81             // Transform a range
82             template<typename OutputIteratorT, typename RangeT, typename FunctorT>
transform_range_copy(OutputIteratorT Output,const RangeT & Input,FunctorT Functor)83             OutputIteratorT transform_range_copy(
84                 OutputIteratorT Output,
85                 const RangeT& Input,
86                 FunctorT Functor)
87             {
88                 return std::transform(
89                     ::boost::begin(Input),
90                     ::boost::end(Input),
91                     Output,
92                     Functor);
93             }
94 
95             // Transform a range (in-place)
96             template<typename RangeT, typename FunctorT>
transform_range(const RangeT & Input,FunctorT Functor)97             void transform_range(
98                 const RangeT& Input,
99                 FunctorT Functor)
100             {
101                 std::transform(
102                     ::boost::begin(Input),
103                     ::boost::end(Input),
104                     ::boost::begin(Input),
105                     Functor);
106             }
107 
108             template<typename SequenceT, typename RangeT, typename FunctorT>
transform_range_copy(const RangeT & Input,FunctorT Functor)109             inline SequenceT transform_range_copy(
110                 const RangeT& Input,
111                 FunctorT Functor)
112             {
113                 return SequenceT(
114                     ::boost::make_transform_iterator(
115                         ::boost::begin(Input),
116                         Functor),
117                     ::boost::make_transform_iterator(
118                         ::boost::end(Input),
119                         Functor));
120             }
121 
122         } // namespace detail
123     } // namespace algorithm
124 } // namespace boost
125 
126 
127 #endif  // BOOST_STRING_CASE_CONV_DETAIL_HPP
128