1
+ /*
2
+ WCharacter.h - Character utility functions for Wiring & Arduino
3
+ Copyright (c) 2010 Hernando Barragan. All right reserved.
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License as published by the Free Software Foundation; either
8
+ version 2.1 of the License, or (at your option) any later version.
9
+
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public
16
+ License along with this library; if not, write to the Free Software
17
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+ #ifndef Character_h
21
+ #define Character_h
22
+
23
+
24
+ #include "WProgram.h"
25
+
26
+ // WCharacter.h prototypes
27
+ inline boolean isAlphaNumeric (int c ) __attribute__((always_inline ));
28
+ inline boolean isAlpha (int c ) __attribute__((always_inline ));
29
+ inline boolean isAscii (int c ) __attribute__((always_inline ));
30
+ inline boolean isWhitespace (int c ) __attribute__((always_inline ));
31
+ inline boolean isControl (int c ) __attribute__((always_inline ));
32
+ inline boolean isDigit (int c ) __attribute__((always_inline ));
33
+ inline boolean isGraph (int c ) __attribute__((always_inline ));
34
+ inline boolean isLowerCase (int c ) __attribute__((always_inline ));
35
+ inline boolean isPrintable (int c ) __attribute__((always_inline ));
36
+ inline boolean isPunct (int c ) __attribute__((always_inline ));
37
+ inline boolean isSpace (int c ) __attribute__((always_inline ));
38
+ inline boolean isUpperCase (int c ) __attribute__((always_inline ));
39
+ inline boolean isHexadecimalDigit (int c ) __attribute__((always_inline ));
40
+ inline int toAscii (int c ) __attribute__((always_inline ));
41
+ inline int toLowerCase (int c ) __attribute__((always_inline ));
42
+ inline int toUpperCase (int c )__attribute__((always_inline ));
43
+
44
+
45
+ // Checks for an alphanumeric character.
46
+ // It is equivalent to (isalpha(c) || isdigit(c)).
47
+ inline boolean isAlphaNumeric (int c )
48
+ {
49
+ return ( isalnum (c ) == 0 ? false : true);
50
+ }
51
+
52
+
53
+ // Checks for an alphabetic character.
54
+ // It is equivalent to (isupper(c) || islower(c)).
55
+ inline boolean isAlpha (int c )
56
+ {
57
+ return ( isalpha (c ) == 0 ? false : true);
58
+ }
59
+
60
+
61
+ // Checks whether c is a 7-bit unsigned char value
62
+ // that fits into the ASCII character set.
63
+ inline boolean isAscii (int c )
64
+ {
65
+ return ( isascii (c ) == 0 ? false : true);
66
+ }
67
+
68
+
69
+ // Checks for a blank character, that is, a space or a tab.
70
+ inline boolean isWhitespace (int c )
71
+ {
72
+ return ( isblank (c ) == 0 ? false : true);
73
+ }
74
+
75
+
76
+ // Checks for a control character.
77
+ inline boolean isControl (int c )
78
+ {
79
+ return ( iscntrl (c ) == 0 ? false : true);
80
+ }
81
+
82
+
83
+ // Checks for a digit (0 through 9).
84
+ inline boolean isDigit (int c )
85
+ {
86
+ return ( isdigit (c ) == 0 ? false : true);
87
+ }
88
+
89
+
90
+ // Checks for any printable character except space.
91
+ inline boolean isGraph (int c )
92
+ {
93
+ return ( isgraph (c ) == 0 ? false : true);
94
+ }
95
+
96
+
97
+ // Checks for a lower-case character.
98
+ inline boolean isLowerCase (int c )
99
+ {
100
+ return (islower (c ) == 0 ? false : true);
101
+ }
102
+
103
+
104
+ // Checks for any printable character including space.
105
+ inline boolean isPrintable (int c )
106
+ {
107
+ return ( isprint (c ) == 0 ? false : true);
108
+ }
109
+
110
+
111
+ // Checks for any printable character which is not a space
112
+ // or an alphanumeric character.
113
+ inline boolean isPunct (int c )
114
+ {
115
+ return ( ispunct (c ) == 0 ? false : true);
116
+ }
117
+
118
+
119
+ // Checks for white-space characters. For the avr-libc library,
120
+ // these are: space, formfeed (’\f’), newline (’\n’), carriage
121
+ // return (’\r’), horizontal tab (’\t’), and vertical tab (’\v’).
122
+ inline boolean isSpace (int c )
123
+ {
124
+ return ( isspace (c ) == 0 ? false : true);
125
+ }
126
+
127
+
128
+ // Checks for an uppercase letter.
129
+ inline boolean isUpperCase (int c )
130
+ {
131
+ return ( isupper (c ) == 0 ? false : true);
132
+ }
133
+
134
+
135
+ // Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7
136
+ // 8 9 a b c d e f A B C D E F.
137
+ inline boolean isHexadecimalDigit (int c )
138
+ {
139
+ return ( isxdigit (c ) == 0 ? false : true);
140
+ }
141
+
142
+
143
+ // Converts c to a 7-bit unsigned char value that fits into the
144
+ // ASCII character set, by clearing the high-order bits.
145
+ inline int toAscii (int c )
146
+ {
147
+ return toascii (c );
148
+ }
149
+
150
+
151
+ // Warning:
152
+ // Many people will be unhappy if you use this function.
153
+ // This function will convert accented letters into random
154
+ // characters.
155
+
156
+ // Converts the letter c to lower case, if possible.
157
+ inline int toLowerCase (int c )
158
+ {
159
+ return tolower (c );
160
+ }
161
+
162
+
163
+ // Converts the letter c to upper case, if possible.
164
+ inline int toUpperCase (int c )
165
+ {
166
+ return toupper (c );
167
+ }
168
+
169
+ #endif
0 commit comments