Line data Source code
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/iterator/transform_iterator.hpp> 19 : #include <boost/range/begin.hpp> 20 : #include <boost/range/end.hpp> 21 : #include <boost/type_traits/make_unsigned.hpp> 22 : 23 : namespace boost { 24 : namespace algorithm { 25 : namespace detail { 26 : 27 : // case conversion functors -----------------------------------------------// 28 : 29 : #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) 30 : #pragma warning(push) 31 : #pragma warning(disable:4512) //assignment operator could not be generated 32 : #endif 33 : 34 : // a tolower functor 35 : template<typename CharT> 36 : struct to_lowerF 37 : { 38 : typedef CharT argument_type; 39 : typedef CharT result_type; 40 : // Constructor 41 1456 : to_lowerF( const std::locale& Loc ) : m_Loc( &Loc ) {} 42 : 43 : // Operation 44 4088 : CharT operator ()( CharT Ch ) const 45 : { 46 : #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL) 47 : return std::tolower( static_cast<typename boost::make_unsigned <CharT>::type> ( Ch )); 48 : #else 49 4088 : return std::tolower<CharT>( Ch, *m_Loc ); 50 : #endif 51 : } 52 : private: 53 : const std::locale* m_Loc; 54 : }; 55 : 56 : // a toupper functor 57 : template<typename CharT> 58 : struct to_upperF 59 : { 60 : typedef CharT argument_type; 61 : typedef CharT result_type; 62 : // Constructor 63 : to_upperF( const std::locale& Loc ) : m_Loc( &Loc ) {} 64 : 65 : // Operation 66 : CharT operator ()( CharT Ch ) const 67 : { 68 : #if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL) 69 : return std::toupper( static_cast<typename boost::make_unsigned <CharT>::type> ( Ch )); 70 : #else 71 : return std::toupper<CharT>( Ch, *m_Loc ); 72 : #endif 73 : } 74 : private: 75 : const std::locale* m_Loc; 76 : }; 77 : 78 : #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) 79 : #pragma warning(pop) 80 : #endif 81 : 82 : // algorithm implementation ------------------------------------------------------------------------- 83 : 84 : // Transform a range 85 : template<typename OutputIteratorT, typename RangeT, typename FunctorT> 86 : OutputIteratorT transform_range_copy( 87 : OutputIteratorT Output, 88 : const RangeT& Input, 89 : FunctorT Functor) 90 : { 91 : return std::transform( 92 : ::boost::begin(Input), 93 : ::boost::end(Input), 94 : Output, 95 : Functor); 96 : } 97 : 98 : // Transform a range (in-place) 99 : template<typename RangeT, typename FunctorT> 100 : void transform_range( 101 : const RangeT& Input, 102 : FunctorT Functor) 103 : { 104 : std::transform( 105 : ::boost::begin(Input), 106 : ::boost::end(Input), 107 : ::boost::begin(Input), 108 : Functor); 109 : } 110 : 111 : template<typename SequenceT, typename RangeT, typename FunctorT> 112 728 : inline SequenceT transform_range_copy( 113 : const RangeT& Input, 114 : FunctorT Functor) 115 : { 116 728 : return SequenceT( 117 728 : ::boost::make_transform_iterator( 118 728 : ::boost::begin(Input), 119 728 : Functor), 120 728 : ::boost::make_transform_iterator( 121 728 : ::boost::end(Input), 122 728 : Functor)); 123 : } 124 : 125 : } // namespace detail 126 : } // namespace algorithm 127 : } // namespace boost 128 : 129 : 130 : #endif // BOOST_STRING_CASE_CONV_DETAIL_HPP