|
| 1 | +// Boost string_algo library case_conv.hpp header file ---------------------------// |
| 2 | + |
| 3 | +// Copyright Pavol Droba 2002-2003. Use, modification and |
| 4 | +// distribution is subject to the Boost Software License, Version |
| 5 | +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 6 | +// http://www.boost.org/LICENSE_1_0.txt) |
| 7 | + |
| 8 | +// See http://www.boost.org for updates, documentation, and revision history. |
| 9 | + |
| 10 | +#ifndef BOOST_STRING_CASE_CONV_HPP |
| 11 | +#define BOOST_STRING_CASE_CONV_HPP |
| 12 | + |
| 13 | +#include <boost/algorithm/string/config.hpp> |
| 14 | +#include <algorithm> |
| 15 | +#include <locale> |
| 16 | +#include <boost/iterator/transform_iterator.hpp> |
| 17 | +#include <boost/algorithm/string/collection_traits.hpp> |
| 18 | +#include <boost/algorithm/string/detail/case_conv.hpp> |
| 19 | + |
| 20 | +/*! \file |
| 21 | + Defines sequence case-conversion algorithms. |
| 22 | + Algorithms convert each element in the input sequence to the |
| 23 | + desired case using provided locales. |
| 24 | +*/ |
| 25 | + |
| 26 | +namespace boost { |
| 27 | + namespace algorithm { |
| 28 | + |
| 29 | +// to_lower -----------------------------------------------// |
| 30 | + |
| 31 | + //! Convert to lower case |
| 32 | + /*! |
| 33 | + Each element of the input sequence is converted to lower |
| 34 | + case. The result is copied to the given output iterator. |
| 35 | +
|
| 36 | + \param Output A output iterator to which the result will be copied |
| 37 | + \param Input An input collection |
| 38 | + \param Loc A locale used for conversion |
| 39 | + \return An output iterator pointing just after last inserted character |
| 40 | + */ |
| 41 | + template<typename OutputIteratorT, typename CollectionT> |
| 42 | + inline OutputIteratorT |
| 43 | + to_lower_copy( |
| 44 | + OutputIteratorT Output, |
| 45 | + const CollectionT& Input, |
| 46 | + const std::locale& Loc=std::locale()) |
| 47 | + { |
| 48 | + return std::transform( |
| 49 | + begin(Input), |
| 50 | + end(Input), |
| 51 | + Output, |
| 52 | + detail::to_lowerF< |
| 53 | + typename value_type_of<CollectionT>::type >(Loc)); |
| 54 | + } |
| 55 | + |
| 56 | + //! Convert to lower case |
| 57 | + /*! |
| 58 | + Each element of the input sequence is converted to lower |
| 59 | + case. The result is a copy of the input converted to lower case. |
| 60 | +
|
| 61 | + \param Input An input sequence |
| 62 | + \param Loc a locale used for conversion |
| 63 | + \return A copy of the input converted to lower case |
| 64 | + */ |
| 65 | + template<typename SequenceT> |
| 66 | + inline SequenceT to_lower_copy( |
| 67 | + const SequenceT& Input, |
| 68 | + const std::locale& Loc=std::locale()) |
| 69 | + { |
| 70 | + return SequenceT( |
| 71 | + make_transform_iterator( |
| 72 | + begin(Input), |
| 73 | + detail::to_lowerF< |
| 74 | + typename value_type_of<SequenceT>::type >(Loc)), |
| 75 | + make_transform_iterator( |
| 76 | + end(Input), |
| 77 | + detail::to_lowerF< |
| 78 | + typename value_type_of<SequenceT>::type >(Loc))); |
| 79 | + } |
| 80 | + |
| 81 | + //! Convert to lower case |
| 82 | + /*! |
| 83 | + Each element of the input sequence is converted to lower |
| 84 | + case. The input sequence is modified in-place. |
| 85 | +
|
| 86 | + \param Input A collection |
| 87 | + \param Loc a locale used for conversion |
| 88 | + */ |
| 89 | + template<typename MutableCollectionT> |
| 90 | + inline void to_lower( |
| 91 | + MutableCollectionT& Input, |
| 92 | + const std::locale& Loc=std::locale()) |
| 93 | + { |
| 94 | + std::transform( |
| 95 | + begin(Input), |
| 96 | + end(Input), |
| 97 | + begin(Input), |
| 98 | + detail::to_lowerF< |
| 99 | + typename value_type_of<MutableCollectionT>::type >(Loc)); |
| 100 | + } |
| 101 | + |
| 102 | +// to_upper -----------------------------------------------// |
| 103 | + |
| 104 | + //! Convert to upper case |
| 105 | + /*! |
| 106 | + Each element of the input sequence is converted to upper |
| 107 | + case. The result is copied to the given output iterator. |
| 108 | +
|
| 109 | + \param Output A output iterator to which the result will be copied |
| 110 | + \param Input An input collection |
| 111 | + \param Loc a locale used for conversion |
| 112 | + \return An output iterator pointing just after last inserted character |
| 113 | + */ |
| 114 | + template<typename OutputIteratorT, typename CollectionT> |
| 115 | + inline OutputIteratorT |
| 116 | + to_upper_copy( |
| 117 | + OutputIteratorT Output, |
| 118 | + const CollectionT& Input, |
| 119 | + const std::locale& Loc=std::locale()) |
| 120 | + { |
| 121 | + return std::transform( |
| 122 | + begin(Input), |
| 123 | + end(Input), |
| 124 | + Output, |
| 125 | + detail::to_upperF< |
| 126 | + typename value_type_of<CollectionT>::type >(Loc)); |
| 127 | + } |
| 128 | + |
| 129 | + //! Convert to upper case |
| 130 | + /*! |
| 131 | + Each element of the input sequence is converted to upper |
| 132 | + case. The result is a copy if the input converted to upper case. |
| 133 | +
|
| 134 | + \param Input An input sequence |
| 135 | + \param Loc a locale used for conversion |
| 136 | + \return A copy of the input converted to upper case |
| 137 | + */ |
| 138 | + template<typename SequenceT> |
| 139 | + inline SequenceT to_upper_copy( |
| 140 | + const SequenceT& Input, |
| 141 | + const std::locale& Loc=std::locale()) |
| 142 | + { |
| 143 | + return SequenceT( |
| 144 | + make_transform_iterator( |
| 145 | + begin(Input), |
| 146 | + detail::to_upperF< |
| 147 | + typename value_type_of<SequenceT>::type >(Loc)), |
| 148 | + make_transform_iterator( |
| 149 | + end(Input), |
| 150 | + detail::to_upperF< |
| 151 | + typename value_type_of<SequenceT>::type >(Loc))); |
| 152 | + |
| 153 | + } |
| 154 | + |
| 155 | + //! Convert to upper case |
| 156 | + /*! |
| 157 | + Each element of the input sequence is converted to upper |
| 158 | + case. The input sequence is modified in-place. |
| 159 | +
|
| 160 | + \param Input An input collection |
| 161 | + \param Loc a locale used for conversion |
| 162 | + */ |
| 163 | + template<typename MutableCollectionT> |
| 164 | + inline void to_upper( |
| 165 | + MutableCollectionT& Input, |
| 166 | + const std::locale& Loc=std::locale()) |
| 167 | + { |
| 168 | + std::transform( |
| 169 | + begin(Input), |
| 170 | + end(Input), |
| 171 | + begin(Input), |
| 172 | + detail::to_upperF< |
| 173 | + typename value_type_of<MutableCollectionT>::type >(Loc)); |
| 174 | + } |
| 175 | + |
| 176 | + } // namespace algorithm |
| 177 | + |
| 178 | + // pull names to the boost namespace |
| 179 | + using algorithm::to_lower; |
| 180 | + using algorithm::to_lower_copy; |
| 181 | + using algorithm::to_upper; |
| 182 | + using algorithm::to_upper_copy; |
| 183 | + |
| 184 | +} // namespace boost |
| 185 | + |
| 186 | +#endif // BOOST_STRING_CASE_CONV_HPP |
0 commit comments