case_conv.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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
  25. {
  26. typedef CharT argument_type;
  27. typedef CharT result_type;
  28. // Constructor
  29. to_lowerF( const std::locale& Loc ) : m_Loc( &Loc ) {}
  30. // Operation
  31. CharT operator ()( CharT Ch ) const
  32. {
  33. #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
  34. return std::tolower( static_cast<typename boost::make_unsigned <CharT>::type> ( Ch ));
  35. #else
  36. return std::tolower<CharT>( Ch, *m_Loc );
  37. #endif
  38. }
  39. private:
  40. const std::locale* m_Loc;
  41. };
  42. // a toupper functor
  43. template<typename CharT>
  44. struct to_upperF
  45. {
  46. typedef CharT argument_type;
  47. typedef CharT result_type;
  48. // Constructor
  49. to_upperF( const std::locale& Loc ) : m_Loc( &Loc ) {}
  50. // Operation
  51. CharT operator ()( CharT Ch ) const
  52. {
  53. #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
  54. return std::toupper( static_cast<typename boost::make_unsigned <CharT>::type> ( Ch ));
  55. #else
  56. return std::toupper<CharT>( Ch, *m_Loc );
  57. #endif
  58. }
  59. private:
  60. const std::locale* m_Loc;
  61. };
  62. #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
  63. #pragma warning(pop)
  64. #endif
  65. // algorithm implementation -------------------------------------------------------------------------
  66. // Transform a range
  67. template<typename OutputIteratorT, typename RangeT, typename FunctorT>
  68. OutputIteratorT transform_range_copy(
  69. OutputIteratorT Output,
  70. const RangeT& Input,
  71. FunctorT Functor)
  72. {
  73. return std::transform(
  74. ::boost::begin(Input),
  75. ::boost::end(Input),
  76. Output,
  77. Functor);
  78. }
  79. // Transform a range (in-place)
  80. template<typename RangeT, typename FunctorT>
  81. void transform_range(
  82. const RangeT& Input,
  83. FunctorT Functor)
  84. {
  85. std::transform(
  86. ::boost::begin(Input),
  87. ::boost::end(Input),
  88. ::boost::begin(Input),
  89. Functor);
  90. }
  91. template<typename SequenceT, typename RangeT, typename FunctorT>
  92. inline SequenceT transform_range_copy(
  93. const RangeT& Input,
  94. FunctorT Functor)
  95. {
  96. return SequenceT(
  97. ::boost::make_transform_iterator(
  98. ::boost::begin(Input),
  99. Functor),
  100. ::boost::make_transform_iterator(
  101. ::boost::end(Input),
  102. Functor));
  103. }
  104. } // namespace detail
  105. } // namespace algorithm
  106. } // namespace boost
  107. #endif // BOOST_STRING_CASE_CONV_DETAIL_HPP