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 | |
---|
18 | #include <boost/range/begin.hpp> |
---|
19 | #include <boost/range/end.hpp> |
---|
20 | #include <boost/range/value_type.hpp> |
---|
21 | |
---|
22 | #include <boost/algorithm/string/detail/case_conv.hpp> |
---|
23 | |
---|
24 | /*! \file |
---|
25 | Defines sequence case-conversion algorithms. |
---|
26 | Algorithms convert each element in the input sequence to the |
---|
27 | desired case using provided locales. |
---|
28 | */ |
---|
29 | |
---|
30 | namespace boost { |
---|
31 | namespace algorithm { |
---|
32 | |
---|
33 | // to_lower -----------------------------------------------// |
---|
34 | |
---|
35 | //! Convert to lower case |
---|
36 | /*! |
---|
37 | Each element of the input sequence is converted to lower |
---|
38 | case. The result is a copy of the input converted to lower case. |
---|
39 | It is returned as a sequence or copied to the output iterator. |
---|
40 | |
---|
41 | \param Output An output iterator to which the result will be copied |
---|
42 | \param Input An input range |
---|
43 | \param Loc A locale used for conversion |
---|
44 | \return |
---|
45 | An output iterator pointing just after the last inserted character or |
---|
46 | a copy of the input |
---|
47 | |
---|
48 | \note The second variant of this function provides the strong exception-safety guarantee |
---|
49 | |
---|
50 | */ |
---|
51 | template<typename OutputIteratorT, typename RangeT> |
---|
52 | inline OutputIteratorT |
---|
53 | to_lower_copy( |
---|
54 | OutputIteratorT Output, |
---|
55 | const RangeT& Input, |
---|
56 | const std::locale& Loc=std::locale()) |
---|
57 | { |
---|
58 | return std::transform( |
---|
59 | begin(Input), |
---|
60 | end(Input), |
---|
61 | Output, |
---|
62 | ::boost::algorithm::detail::to_lowerF< |
---|
63 | typename range_value<RangeT>::type >(Loc)); |
---|
64 | } |
---|
65 | |
---|
66 | //! Convert to lower case |
---|
67 | /*! |
---|
68 | \overload |
---|
69 | */ |
---|
70 | template<typename SequenceT> |
---|
71 | inline SequenceT to_lower_copy( |
---|
72 | const SequenceT& Input, |
---|
73 | const std::locale& Loc=std::locale()) |
---|
74 | { |
---|
75 | return SequenceT( |
---|
76 | make_transform_iterator( |
---|
77 | begin(Input), |
---|
78 | ::boost::algorithm::detail::to_lowerF< |
---|
79 | typename range_value<SequenceT>::type >(Loc)), |
---|
80 | make_transform_iterator( |
---|
81 | end(Input), |
---|
82 | ::boost::algorithm::detail::to_lowerF< |
---|
83 | typename range_value<SequenceT>::type >(Loc))); |
---|
84 | } |
---|
85 | |
---|
86 | //! Convert to lower case |
---|
87 | /*! |
---|
88 | Each element of the input sequence is converted to lower |
---|
89 | case. The input sequence is modified in-place. |
---|
90 | |
---|
91 | \param Input A range |
---|
92 | \param Loc a locale used for conversion |
---|
93 | */ |
---|
94 | template<typename WritableRangeT> |
---|
95 | inline void to_lower( |
---|
96 | WritableRangeT& Input, |
---|
97 | const std::locale& Loc=std::locale()) |
---|
98 | { |
---|
99 | std::transform( |
---|
100 | begin(Input), |
---|
101 | end(Input), |
---|
102 | begin(Input), |
---|
103 | ::boost::algorithm::detail::to_lowerF< |
---|
104 | typename range_value<WritableRangeT>::type >(Loc)); |
---|
105 | } |
---|
106 | |
---|
107 | // to_upper -----------------------------------------------// |
---|
108 | |
---|
109 | //! Convert to upper case |
---|
110 | /*! |
---|
111 | Each element of the input sequence is converted to upper |
---|
112 | case. The result is a copy of the input converted to upper case. |
---|
113 | It is returned as a sequence or copied to the output iterator |
---|
114 | |
---|
115 | \param Output An output iterator to which the result will be copied |
---|
116 | \param Input An input range |
---|
117 | \param Loc A locale used for conversion |
---|
118 | \return |
---|
119 | An output iterator pointing just after the last inserted character or |
---|
120 | a copy of the input |
---|
121 | |
---|
122 | \note The second variant of this function provides the strong exception-safety guarantee |
---|
123 | */ |
---|
124 | template<typename OutputIteratorT, typename RangeT> |
---|
125 | inline OutputIteratorT |
---|
126 | to_upper_copy( |
---|
127 | OutputIteratorT Output, |
---|
128 | const RangeT& Input, |
---|
129 | const std::locale& Loc=std::locale()) |
---|
130 | { |
---|
131 | return std::transform( |
---|
132 | begin(Input), |
---|
133 | end(Input), |
---|
134 | Output, |
---|
135 | ::boost::algorithm::detail::to_upperF< |
---|
136 | typename range_value<RangeT>::type >(Loc)); |
---|
137 | } |
---|
138 | |
---|
139 | //! Convert to upper case |
---|
140 | /*! |
---|
141 | \overload |
---|
142 | */ |
---|
143 | template<typename SequenceT> |
---|
144 | inline SequenceT to_upper_copy( |
---|
145 | const SequenceT& Input, |
---|
146 | const std::locale& Loc=std::locale()) |
---|
147 | { |
---|
148 | return SequenceT( |
---|
149 | make_transform_iterator( |
---|
150 | begin(Input), |
---|
151 | ::boost::algorithm::detail::to_upperF< |
---|
152 | typename range_value<SequenceT>::type >(Loc)), |
---|
153 | make_transform_iterator( |
---|
154 | end(Input), |
---|
155 | ::boost::algorithm::detail::to_upperF< |
---|
156 | typename range_value<SequenceT>::type >(Loc))); |
---|
157 | |
---|
158 | } |
---|
159 | |
---|
160 | //! Convert to upper case |
---|
161 | /*! |
---|
162 | Each element of the input sequence is converted to upper |
---|
163 | case. The input sequence is modified in-place. |
---|
164 | |
---|
165 | \param Input An input range |
---|
166 | \param Loc a locale used for conversion |
---|
167 | */ |
---|
168 | template<typename WritableRangeT> |
---|
169 | inline void to_upper( |
---|
170 | WritableRangeT& Input, |
---|
171 | const std::locale& Loc=std::locale()) |
---|
172 | { |
---|
173 | std::transform( |
---|
174 | begin(Input), |
---|
175 | end(Input), |
---|
176 | begin(Input), |
---|
177 | ::boost::algorithm::detail::to_upperF< |
---|
178 | typename range_value<WritableRangeT>::type >(Loc)); |
---|
179 | } |
---|
180 | |
---|
181 | } // namespace algorithm |
---|
182 | |
---|
183 | // pull names to the boost namespace |
---|
184 | using algorithm::to_lower; |
---|
185 | using algorithm::to_lower_copy; |
---|
186 | using algorithm::to_upper; |
---|
187 | using algorithm::to_upper_copy; |
---|
188 | |
---|
189 | } // namespace boost |
---|
190 | |
---|
191 | #endif // BOOST_STRING_CASE_CONV_HPP |
---|