case_conv.hpp 4.2 KB

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