case_conv.hpp 4.0 KB

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