monotone

monotone Mtn Source Tree

Root/char_classifiers.hh

1#ifndef __CHAR_CLASSIFIERS_HH__
2#define __CHAR_CLASSIFIERS_HH__
3
4// Copyright (C) 2004 Graydon Hoare <graydon@pobox.com>
5//
6// This program is made available under the GNU GPL version 2.0 or
7// greater. See the accompanying file COPYING for details.
8//
9// This program is distributed WITHOUT ANY WARRANTY; without even the
10// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11// PURPOSE.
12
13// We don't use the standard C <ctype.h> macros because their results
14// may depend on the global locale, and we don't use the standard C++
15// <locale> ctype facet (in classic() mode, of course) because, well,
16// someone should try it and verify that it's not slower.
17
18// Yes, we are aware that these will break horribly with EBCDIC.
19
20inline bool is_digit(char x)
21{
22 return (x >= '0' && x <= '9');
23}
24
25inline bool is_xdigit(char x)
26{
27 return ((x >= '0' && x <= '9')
28 || (x >= 'a' && x <= 'f'));
29}
30
31inline bool is_alpha(char x)
32{
33 return ((x >= 'a' && x <= 'z')
34 || (x >= 'A' && x <= 'Z'));
35}
36
37inline bool is_alnum(char x)
38{
39 return ((x >= '0' && x <= '9')
40 || (x >= 'a' && x <= 'z')
41 || (x >= 'A' && x <= 'Z'));
42}
43
44inline bool is_space(char x)
45{
46 return (x == ' ')
47 || (x == '\n')
48 || (x == '\t')
49 || (x == '\r')
50 || (x == '\v')
51 || (x == '\f');
52}
53
54inline bool is_upper(char x)
55{
56 return (x >= 'A' && x <= 'Z');
57}
58
59inline bool is_lower(char x)
60{
61 return (x >= 'a' && x <= 'z');
62}
63
64inline char to_upper(char x)
65{
66 return is_lower(x) ? (x - 'a' + 'A') : x;
67}
68
69inline char to_lower(char x)
70{
71 return is_upper(x) ? (x - 'A' + 'a') : x;
72}
73
74// Local Variables:
75// mode: C++
76// fill-column: 76
77// c-file-style: "gnu"
78// indent-tabs-mode: nil
79// End:
80// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
81
82#endif // __CHAR_CLASSIFIERS_HH__

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status