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