case_conv.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // Boost string_algo library case_conv.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_HPP
  9. #define BOOST_STRING_CASE_CONV_HPP
  10. #include <boost/algorithm/string/config.hpp>
  11. #include <algorithm>
  12. #include <locale>
  13. #include <boost/iterator/transform_iterator.hpp>
  14. #include <boost/range/as_literal.hpp>
  15. #include <boost/range/begin.hpp>
  16. #include <boost/range/end.hpp>
  17. #include <boost/range/value_type.hpp>
  18. #include <boost/algorithm/string/detail/case_conv.hpp>
  19. /*! \file
  20. Defines sequence case-conversion algorithms.
  21. Algorithms convert each element in the input sequence to the
  22. desired case using provided locales.
  23. */
  24. namespace boost {
  25. namespace algorithm {
  26. // to_lower -----------------------------------------------//
  27. //! Convert to lower case
  28. /*!
  29. Each element of the input sequence is converted to lower
  30. case. The result is a copy of the input converted to lower case.
  31. It is returned as a sequence or copied to the output iterator.
  32. \param Output An output iterator to which the result will be copied
  33. \param Input An input range
  34. \param Loc A locale used for conversion
  35. \return
  36. An output iterator pointing just after the last inserted character or
  37. a copy of the input
  38. \note The second variant of this function provides the strong exception-safety guarantee
  39. */
  40. template<typename OutputIteratorT, typename RangeT>
  41. inline OutputIteratorT
  42. to_lower_copy(
  43. OutputIteratorT Output,
  44. const RangeT& Input,
  45. const std::locale& Loc=std::locale())
  46. {
  47. return ::boost::algorithm::detail::transform_range_copy(
  48. Output,
  49. ::boost::as_literal(Input),
  50. ::boost::algorithm::detail::to_lowerF<
  51. typename range_value<RangeT>::type >(Loc));
  52. }
  53. //! Convert to lower case
  54. /*!
  55. \overload
  56. */
  57. template<typename SequenceT>
  58. inline SequenceT to_lower_copy(
  59. const SequenceT& Input,
  60. const std::locale& Loc=std::locale())
  61. {
  62. return ::boost::algorithm::detail::transform_range_copy<SequenceT>(
  63. Input,
  64. ::boost::algorithm::detail::to_lowerF<
  65. typename range_value<SequenceT>::type >(Loc));
  66. }
  67. //! Convert to lower case
  68. /*!
  69. Each element of the input sequence is converted to lower
  70. case. The input sequence is modified in-place.
  71. \param Input A range
  72. \param Loc a locale used for conversion
  73. */
  74. template<typename WritableRangeT>
  75. inline void to_lower(
  76. WritableRangeT& Input,
  77. const std::locale& Loc=std::locale())
  78. {
  79. ::boost::algorithm::detail::transform_range(
  80. ::boost::as_literal(Input),
  81. ::boost::algorithm::detail::to_lowerF<
  82. typename range_value<WritableRangeT>::type >(Loc));
  83. }
  84. // to_upper -----------------------------------------------//
  85. //! Convert to upper case
  86. /*!
  87. Each element of the input sequence is converted to upper
  88. case. The result is a copy of the input converted to upper case.
  89. It is returned as a sequence or copied to the output iterator
  90. \param Output An output iterator to which the result will be copied
  91. \param Input An input range
  92. \param Loc A locale used for conversion
  93. \return
  94. An output iterator pointing just after the last inserted character or
  95. a copy of the input
  96. \note The second variant of this function provides the strong exception-safety guarantee
  97. */
  98. template<typename OutputIteratorT, typename RangeT>
  99. inline OutputIteratorT
  100. to_upper_copy(
  101. OutputIteratorT Output,
  102. const RangeT& Input,
  103. const std::locale& Loc=std::locale())
  104. {
  105. return ::boost::algorithm::detail::transform_range_copy(
  106. Output,
  107. ::boost::as_literal(Input),
  108. ::boost::algorithm::detail::to_upperF<
  109. typename range_value<RangeT>::type >(Loc));
  110. }
  111. //! Convert to upper case
  112. /*!
  113. \overload
  114. */
  115. template<typename SequenceT>
  116. inline SequenceT to_upper_copy(
  117. const SequenceT& Input,
  118. const std::locale& Loc=std::locale())
  119. {
  120. return ::boost::algorithm::detail::transform_range_copy<SequenceT>(
  121. Input,
  122. ::boost::algorithm::detail::to_upperF<
  123. typename range_value<SequenceT>::type >(Loc));
  124. }
  125. //! Convert to upper case
  126. /*!
  127. Each element of the input sequence is converted to upper
  128. case. The input sequence is modified in-place.
  129. \param Input An input range
  130. \param Loc a locale used for conversion
  131. */
  132. template<typename WritableRangeT>
  133. inline void to_upper(
  134. WritableRangeT& Input,
  135. const std::locale& Loc=std::locale())
  136. {
  137. ::boost::algorithm::detail::transform_range(
  138. ::boost::as_literal(Input),
  139. ::boost::algorithm::detail::to_upperF<
  140. typename range_value<WritableRangeT>::type >(Loc));
  141. }
  142. } // namespace algorithm
  143. // pull names to the boost namespace
  144. using algorithm::to_lower;
  145. using algorithm::to_lower_copy;
  146. using algorithm::to_upper;
  147. using algorithm::to_upper_copy;
  148. } // namespace boost
  149. #endif // BOOST_STRING_CASE_CONV_HPP