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