1 | // Boost string_algo library classification.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_CLASSIFICATION_HPP
|
---|
11 | #define BOOST_STRING_CLASSIFICATION_HPP
|
---|
12 |
|
---|
13 | #include <algorithm>
|
---|
14 | #include <locale>
|
---|
15 | #include <boost/range/value_type.hpp>
|
---|
16 | #include <boost/algorithm/string/detail/classification.hpp>
|
---|
17 | #include <boost/algorithm/string/predicate_facade.hpp>
|
---|
18 |
|
---|
19 | /*! \file
|
---|
20 | Classification predicates are included in the library to give
|
---|
21 | some more convenience when using algorithms like \c trim() and \c all().
|
---|
22 | They wrap functionality of STL classification functions ( e.g. \c std::isspace() )
|
---|
23 | into generic functors.
|
---|
24 | */
|
---|
25 |
|
---|
26 | namespace boost {
|
---|
27 | namespace algorithm {
|
---|
28 |
|
---|
29 | // classification functor generator -------------------------------------//
|
---|
30 |
|
---|
31 | //! is_classified predicate
|
---|
32 | /*!
|
---|
33 | Construct the \c is_classified predicate. This predicate holds if the input is
|
---|
34 | of specified \c std::ctype category.
|
---|
35 |
|
---|
36 | \param Type A \c std::ctype category
|
---|
37 | \param Loc A locale used for classification
|
---|
38 | \return An instance of the \c is_classified predicate
|
---|
39 | */
|
---|
40 | inline detail::is_classifiedF
|
---|
41 | is_classified(std::ctype_base::mask Type, const std::locale& Loc=std::locale())
|
---|
42 | {
|
---|
43 | return detail::is_classifiedF(Type, Loc);
|
---|
44 | }
|
---|
45 |
|
---|
46 | //! is_space predicate
|
---|
47 | /*!
|
---|
48 | Construct the \c is_classified predicate for the \c ctype_base::space category.
|
---|
49 |
|
---|
50 | \param Loc A locale used for classification
|
---|
51 | \return An instance of the \c is_classified predicate
|
---|
52 | */
|
---|
53 | inline detail::is_classifiedF
|
---|
54 | is_space(const std::locale& Loc=std::locale())
|
---|
55 | {
|
---|
56 | return detail::is_classifiedF(std::ctype_base::space, Loc);
|
---|
57 | }
|
---|
58 |
|
---|
59 | //! is_alnum predicate
|
---|
60 | /*!
|
---|
61 | Construct the \c is_classified predicate for the \c ctype_base::alnum category.
|
---|
62 |
|
---|
63 | \param Loc A locale used for classification
|
---|
64 | \return An instance of the \c is_classified predicate
|
---|
65 | */
|
---|
66 | inline detail::is_classifiedF
|
---|
67 | is_alnum(const std::locale& Loc=std::locale())
|
---|
68 | {
|
---|
69 | return detail::is_classifiedF(std::ctype_base::alnum, Loc);
|
---|
70 | }
|
---|
71 |
|
---|
72 | //! is_alpha predicate
|
---|
73 | /*!
|
---|
74 | Construct the \c is_classified predicate for the \c ctype_base::alpha category.
|
---|
75 |
|
---|
76 | \param Loc A locale used for classification
|
---|
77 | \return An instance of the \c is_classified predicate
|
---|
78 | */
|
---|
79 | inline detail::is_classifiedF
|
---|
80 | is_alpha(const std::locale& Loc=std::locale())
|
---|
81 | {
|
---|
82 | return detail::is_classifiedF(std::ctype_base::alpha, Loc);
|
---|
83 | }
|
---|
84 |
|
---|
85 | //! is_cntrl predicate
|
---|
86 | /*!
|
---|
87 | Construct the \c is_classified predicate for the \c ctype_base::cntrl category.
|
---|
88 |
|
---|
89 | \param Loc A locale used for classification
|
---|
90 | \return An instance of the \c is_classified predicate
|
---|
91 | */
|
---|
92 | inline detail::is_classifiedF
|
---|
93 | is_cntrl(const std::locale& Loc=std::locale())
|
---|
94 | {
|
---|
95 | return detail::is_classifiedF(std::ctype_base::cntrl, Loc);
|
---|
96 | }
|
---|
97 |
|
---|
98 | //! is_digit predicate
|
---|
99 | /*!
|
---|
100 | Construct the \c is_classified predicate for the \c ctype_base::digit category.
|
---|
101 |
|
---|
102 | \param Loc A locale used for classification
|
---|
103 | \return An instance of the \c is_classified predicate
|
---|
104 | */
|
---|
105 | inline detail::is_classifiedF
|
---|
106 | is_digit(const std::locale& Loc=std::locale())
|
---|
107 | {
|
---|
108 | return detail::is_classifiedF(std::ctype_base::digit, Loc);
|
---|
109 | }
|
---|
110 |
|
---|
111 | //! is_graph predicate
|
---|
112 | /*!
|
---|
113 | Construct the \c is_classified predicate for the \c ctype_base::graph category.
|
---|
114 |
|
---|
115 | \param Loc A locale used for classification
|
---|
116 | \return An instance of the \c is_classified predicate
|
---|
117 | */
|
---|
118 | inline detail::is_classifiedF
|
---|
119 | is_graph(const std::locale& Loc=std::locale())
|
---|
120 | {
|
---|
121 | return detail::is_classifiedF(std::ctype_base::graph, Loc);
|
---|
122 | }
|
---|
123 |
|
---|
124 | //! is_lower predicate
|
---|
125 | /*!
|
---|
126 | Construct the \c is_classified predicate for the \c ctype_base::lower category.
|
---|
127 |
|
---|
128 | \param Loc A locale used for classification
|
---|
129 | \return An instance of \c is_classified predicate
|
---|
130 | */
|
---|
131 | inline detail::is_classifiedF
|
---|
132 | is_lower(const std::locale& Loc=std::locale())
|
---|
133 | {
|
---|
134 | return detail::is_classifiedF(std::ctype_base::lower, Loc);
|
---|
135 | }
|
---|
136 |
|
---|
137 | //! is_print predicate
|
---|
138 | /*!
|
---|
139 | Construct the \c is_classified predicate for the \c ctype_base::print category.
|
---|
140 |
|
---|
141 | \param Loc A locale used for classification
|
---|
142 | \return An instance of the \c is_classified predicate
|
---|
143 | */
|
---|
144 | inline detail::is_classifiedF
|
---|
145 | is_print(const std::locale& Loc=std::locale())
|
---|
146 | {
|
---|
147 | return detail::is_classifiedF(std::ctype_base::print, Loc);
|
---|
148 | }
|
---|
149 |
|
---|
150 | //! is_punct predicate
|
---|
151 | /*!
|
---|
152 | Construct the \c is_classified predicate for the \c ctype_base::punct category.
|
---|
153 |
|
---|
154 | \param Loc A locale used for classification
|
---|
155 | \return An instance of the \c is_classified predicate
|
---|
156 | */
|
---|
157 | inline detail::is_classifiedF
|
---|
158 | is_punct(const std::locale& Loc=std::locale())
|
---|
159 | {
|
---|
160 | return detail::is_classifiedF(std::ctype_base::punct, Loc);
|
---|
161 | }
|
---|
162 |
|
---|
163 | //! is_upper predicate
|
---|
164 | /*!
|
---|
165 | Construct the \c is_classified predicate for the \c ctype_base::upper category.
|
---|
166 |
|
---|
167 | \param Loc A locale used for classification
|
---|
168 | \return An instance of the \c is_classified predicate
|
---|
169 | */
|
---|
170 | inline detail::is_classifiedF
|
---|
171 | is_upper(const std::locale& Loc=std::locale())
|
---|
172 | {
|
---|
173 | return detail::is_classifiedF(std::ctype_base::upper, Loc);
|
---|
174 | }
|
---|
175 |
|
---|
176 | //! is_xdigit predicate
|
---|
177 | /*!
|
---|
178 | Construct the \c is_classified predicate for the \c ctype_base::xdigit category.
|
---|
179 |
|
---|
180 | \param Loc A locale used for classification
|
---|
181 | \return An instance of the \c is_classified predicate
|
---|
182 | */
|
---|
183 | inline detail::is_classifiedF
|
---|
184 | is_xdigit(const std::locale& Loc=std::locale())
|
---|
185 | {
|
---|
186 | return detail::is_classifiedF(std::ctype_base::xdigit, Loc);
|
---|
187 | }
|
---|
188 |
|
---|
189 | //! is_any_of predicate
|
---|
190 | /*!
|
---|
191 | Construct the \c is_any_of predicate. The predicate holds if the input
|
---|
192 | is included in the specified set of characters.
|
---|
193 |
|
---|
194 | \param Set A set of characters to be recognized
|
---|
195 | \return An instance of the \c is_any_of predicate
|
---|
196 | */
|
---|
197 | template<typename RangeT>
|
---|
198 | inline detail::is_any_ofF<
|
---|
199 | BOOST_STRING_TYPENAME range_value<RangeT>::type>
|
---|
200 | is_any_of( const RangeT& Set )
|
---|
201 | {
|
---|
202 | return detail::is_any_ofF<
|
---|
203 | BOOST_STRING_TYPENAME range_value<RangeT>::type>(Set);
|
---|
204 | }
|
---|
205 |
|
---|
206 | //! is_from_range predicate
|
---|
207 | /*!
|
---|
208 | Construct the \c is_from_range predicate. The predicate holds if the input
|
---|
209 | is included in the specified range. (i.e. From <= Ch <= To )
|
---|
210 |
|
---|
211 | \param From The start of the range
|
---|
212 | \param To The end of the range
|
---|
213 | \return An instance of the \c is_from_range predicate
|
---|
214 | */
|
---|
215 | template<typename CharT>
|
---|
216 | inline detail::is_from_rangeF<CharT> is_from_range(CharT From, CharT To)
|
---|
217 | {
|
---|
218 | return detail::is_from_rangeF<CharT>(From,To);
|
---|
219 | }
|
---|
220 |
|
---|
221 | // predicate combinators ---------------------------------------------------//
|
---|
222 |
|
---|
223 | //! predicate 'and' composition predicate
|
---|
224 | /*!
|
---|
225 | Construct the \c class_and predicate. This predicate can be used
|
---|
226 | to logically combine two classification predicates. \c class_and holds,
|
---|
227 | if both predicates return true.
|
---|
228 |
|
---|
229 | \param Pred1 The first predicate
|
---|
230 | \param Pred2 The second predicate
|
---|
231 | \return An instance of the \c class_and predicate
|
---|
232 | */
|
---|
233 | template<typename Pred1T, typename Pred2T>
|
---|
234 | inline detail::pred_andF<Pred1T, Pred2T>
|
---|
235 | operator&&(
|
---|
236 | const predicate_facade<Pred1T>& Pred1,
|
---|
237 | const predicate_facade<Pred2T>& Pred2 )
|
---|
238 | {
|
---|
239 | // Doing the static_cast with the pointer instead of the reference
|
---|
240 | // is a workaround for some compilers which have problems with
|
---|
241 | // static_cast's of template references, i.e. CW8. /grafik/
|
---|
242 | return detail::pred_andF<Pred1T,Pred2T>(
|
---|
243 | *static_cast<const Pred1T*>(&Pred1),
|
---|
244 | *static_cast<const Pred2T*>(&Pred2) );
|
---|
245 | }
|
---|
246 |
|
---|
247 | //! predicate 'or' composition predicate
|
---|
248 | /*!
|
---|
249 | Construct the \c class_or predicate. This predicate can be used
|
---|
250 | to logically combine two classification predicates. \c class_or holds,
|
---|
251 | if one of the predicates return true.
|
---|
252 |
|
---|
253 | \param Pred1 The first predicate
|
---|
254 | \param Pred2 The second predicate
|
---|
255 | \return An instance of the \c class_or predicate
|
---|
256 | */
|
---|
257 | template<typename Pred1T, typename Pred2T>
|
---|
258 | inline detail::pred_orF<Pred1T, Pred2T>
|
---|
259 | operator||(
|
---|
260 | const predicate_facade<Pred1T>& Pred1,
|
---|
261 | const predicate_facade<Pred2T>& Pred2 )
|
---|
262 | {
|
---|
263 | // Doing the static_cast with the pointer instead of the reference
|
---|
264 | // is a workaround for some compilers which have problems with
|
---|
265 | // static_cast's of template references, i.e. CW8. /grafik/
|
---|
266 | return detail::pred_orF<Pred1T,Pred2T>(
|
---|
267 | *static_cast<const Pred1T*>(&Pred1),
|
---|
268 | *static_cast<const Pred2T*>(&Pred2));
|
---|
269 | }
|
---|
270 |
|
---|
271 | //! predicate negation operator
|
---|
272 | /*!
|
---|
273 | Construct the \c class_not predicate. This predicate represents a negation.
|
---|
274 | \c class_or holds if of the predicates return false.
|
---|
275 |
|
---|
276 | \param Pred The predicate to be negated
|
---|
277 | \return An instance of the \c class_not predicate
|
---|
278 | */
|
---|
279 | template<typename PredT>
|
---|
280 | inline detail::pred_notF<PredT>
|
---|
281 | operator!( const predicate_facade<PredT>& Pred )
|
---|
282 | {
|
---|
283 | // Doing the static_cast with the pointer instead of the reference
|
---|
284 | // is a workaround for some compilers which have problems with
|
---|
285 | // static_cast's of template references, i.e. CW8. /grafik/
|
---|
286 | return detail::pred_notF<PredT>(*static_cast<const PredT*>(&Pred));
|
---|
287 | }
|
---|
288 |
|
---|
289 | } // namespace algorithm
|
---|
290 |
|
---|
291 | // pull names to the boost namespace
|
---|
292 | using algorithm::is_classified;
|
---|
293 | using algorithm::is_space;
|
---|
294 | using algorithm::is_alnum;
|
---|
295 | using algorithm::is_alpha;
|
---|
296 | using algorithm::is_cntrl;
|
---|
297 | using algorithm::is_digit;
|
---|
298 | using algorithm::is_graph;
|
---|
299 | using algorithm::is_lower;
|
---|
300 | using algorithm::is_upper;
|
---|
301 | using algorithm::is_print;
|
---|
302 | using algorithm::is_punct;
|
---|
303 | using algorithm::is_xdigit;
|
---|
304 | using algorithm::is_any_of;
|
---|
305 | using algorithm::is_from_range;
|
---|
306 |
|
---|
307 | } // namespace boost
|
---|
308 |
|
---|
309 | #endif // BOOST_STRING_PREDICATE_HPP
|
---|