case_conv.hpp 4.4 KB

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