All Classes Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
classification.hpp
1 // The MIT License (MIT)
2 
3 // Copyright (c) 2012-2014 Danny Y., Rapptz
4 
5 // Permission is hereby granted, free of charge, to any person obtaining a copy of
6 // this software and associated documentation files (the "Software"), to deal in
7 // the Software without restriction, including without limitation the rights to
8 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 // the Software, and to permit persons to whom the Software is furnished to do so,
10 // subject to the following conditions:
11 
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 
22 #ifndef GEARS_STRING_CLASSIFICATION_HPP
23 #define GEARS_STRING_CLASSIFICATION_HPP
24 
25 #include <locale>
26 
33 namespace gears {
34 namespace string {
41 struct is_lower {
42 private:
43  std::locale loc;
44 public:
48  is_lower(const std::locale& loc = std::locale()): loc(loc) {}
49 
50  template<typename CharT>
51  bool operator()(CharT c) const {
52  return std::islower(c, loc);
53  }
54 };
55 
62 struct is_upper {
63 private:
64  std::locale loc;
65 public:
69  is_upper(const std::locale& loc = std::locale()): loc(loc) {}
70 
71  template<typename CharT>
72  bool operator()(CharT c) const {
73  return std::isupper(c, loc);
74  }
75 };
76 
83 struct is_space {
84 private:
85  std::locale loc;
86 public:
90  is_space(const std::locale& loc = std::locale()): loc(loc) {}
91 
92  template<typename CharT>
93  bool operator()(CharT c) const {
94  return std::isspace(c, loc);
95  }
96 };
97 
104 struct is_cntrl {
105 private:
106  std::locale loc;
107 public:
111  is_cntrl(const std::locale& loc = std::locale()): loc(loc) {}
112 
113  template<typename CharT>
114  bool operator()(CharT c) const {
115  return std::iscntrl(c, loc);
116  }
117 };
118 
125 struct is_alpha {
126 private:
127  std::locale loc;
128 public:
132  is_alpha(const std::locale& loc = std::locale()): loc(loc) {}
133 
134  template<typename CharT>
135  bool operator()(CharT c) const {
136  return std::isalpha(c, loc);
137  }
138 };
139 
146 struct is_digit {
147 private:
148  std::locale loc;
149 public:
153  is_digit(const std::locale& loc = std::locale()): loc(loc) {}
154 
155  template<typename CharT>
156  bool operator()(CharT c) const {
157  return std::isdigit(c, loc);
158  }
159 };
160 
167 struct is_punct {
168 private:
169  std::locale loc;
170 public:
174  is_punct(const std::locale& loc = std::locale()): loc(loc) {}
175 
176  template<typename CharT>
177  bool operator()(CharT c) const {
178  return std::ispunct(c, loc);
179  }
180 };
181 
188 struct is_alnum {
189 private:
190  std::locale loc;
191 public:
195  is_alnum(const std::locale& loc = std::locale()): loc(loc) {}
196 
197  template<typename CharT>
198  bool operator()(CharT c) const {
199  return std::isalnum(c, loc);
200  }
201 };
202 
209 struct is_print {
210 private:
211  std::locale loc;
212 public:
216  is_print(const std::locale& loc = std::locale()): loc(loc) {}
217 
218  template<typename CharT>
219  bool operator()(CharT c) const {
220  return std::isprint(c, loc);
221  }
222 };
223 
230 struct is_graph {
231 private:
232  std::locale loc;
233 public:
237  is_graph(const std::locale& loc = std::locale()): loc(loc) {}
238 
239  template<typename CharT>
240  bool operator()(CharT c) const {
241  return std::isgraph(c, loc);
242  }
243 };
244 
251 struct is_xdigit {
252 private:
253  std::locale loc;
254 public:
258  is_xdigit(const std::locale& loc = std::locale()): loc(loc) {}
259 
260  template<typename CharT>
261  bool operator()(CharT c) const {
262  return std::isxdigit(c, loc);
263  }
264 };
265 } // string
266 } // gears
267 
268 #endif // GEARS_STRING_CLASSIFICATION_HPP