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
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
18
*/
19
-
20
- #ifndef Character_h
21
- #define Character_h
19
+ #ifndef CHARACTER_H
20
+ #define CHARACTER_H
22
21
23
22
#include <ctype.h>
24
23
@@ -41,131 +40,115 @@ inline bool isUpperCase(int c) __attribute__((always_inline));
41
40
inline bool isHexadecimalDigit (int c ) __attribute__((always_inline ));
42
41
inline int toAscii (int c ) __attribute__((always_inline ));
43
42
inline int toLowerCase (int c ) __attribute__((always_inline ));
44
- inline int toUpperCase (int c )__attribute__((always_inline ));
45
-
43
+ inline int toUpperCase (int c ) __attribute__((always_inline ));
46
44
47
- // Checks for an alphanumeric character.
45
+ // Checks for an alphanumeric character.
48
46
// It is equivalent to (isalpha(c) || isdigit(c)).
49
- inline bool isAlphaNumeric (int c )
47
+ inline bool isAlphaNumeric (int c )
50
48
{
51
- return ( isalnum (c ) == 0 ? false : true);
49
+ return (isalnum (c ) == 0 ? false : true);
52
50
}
53
51
54
-
55
- // Checks for an alphabetic character.
52
+ // Checks for an alphabetic character.
56
53
// It is equivalent to (isupper(c) || islower(c)).
57
54
inline bool isAlpha (int c )
58
55
{
59
- return ( isalpha (c ) == 0 ? false : true);
56
+ return (isalpha (c ) == 0 ? false : true);
60
57
}
61
58
62
-
63
- // Checks whether c is a 7-bit unsigned char value
59
+ // Checks whether c is a 7-bit unsigned char value
64
60
// that fits into the ASCII character set.
65
61
inline bool isAscii (int c )
66
62
{
67
- return ( isascii (c ) == 0 ? false : true);
63
+ return (isascii (c ) == 0 ? false : true);
68
64
}
69
65
70
-
71
66
// Checks for a blank character, that is, a space or a tab.
72
67
inline bool isWhitespace (int c )
73
68
{
74
- return ( isblank (c ) == 0 ? false : true);
69
+ return (isblank (c ) == 0 ? false : true);
75
70
}
76
71
77
-
78
72
// Checks for a control character.
79
73
inline bool isControl (int c )
80
74
{
81
- return ( iscntrl (c ) == 0 ? false : true);
75
+ return (iscntrl (c ) == 0 ? false : true);
82
76
}
83
77
84
-
85
78
// Checks for a digit (0 through 9).
86
79
inline bool isDigit (int c )
87
80
{
88
- return ( isdigit (c ) == 0 ? false : true);
81
+ return (isdigit (c ) == 0 ? false : true);
89
82
}
90
83
91
-
92
84
// Checks for any printable character except space.
93
85
inline bool isGraph (int c )
94
86
{
95
- return ( isgraph (c ) == 0 ? false : true);
87
+ return (isgraph (c ) == 0 ? false : true);
96
88
}
97
89
98
-
99
90
// Checks for a lower-case character.
100
91
inline bool isLowerCase (int c )
101
92
{
102
- return (islower (c ) == 0 ? false : true);
93
+ return (islower (c ) == 0 ? false : true);
103
94
}
104
95
105
-
106
96
// Checks for any printable character including space.
107
97
inline bool isPrintable (int c )
108
98
{
109
- return ( isprint (c ) == 0 ? false : true);
99
+ return (isprint (c ) == 0 ? false : true);
110
100
}
111
101
112
-
113
- // Checks for any printable character which is not a space
102
+ // Checks for any printable character which is not a space
114
103
// or an alphanumeric character.
115
104
inline bool isPunct (int c )
116
105
{
117
- return ( ispunct (c ) == 0 ? false : true);
106
+ return (ispunct (c ) == 0 ? false : true);
118
107
}
119
108
120
-
121
- // Checks for white-space characters. For the avr-libc library,
122
- // these are: space, formfeed ('\f'), newline ('\n'), carriage
109
+ // Checks for white-space characters. For the avr-libc library,
110
+ // these are: space, formfeed ('\f'), newline ('\n'), carriage
123
111
// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
124
112
inline bool isSpace (int c )
125
113
{
126
- return ( isspace (c ) == 0 ? false : true);
114
+ return (isspace (c ) == 0 ? false : true);
127
115
}
128
116
129
-
130
117
// Checks for an uppercase letter.
131
118
inline bool isUpperCase (int c )
132
119
{
133
- return ( isupper (c ) == 0 ? false : true);
120
+ return (isupper (c ) == 0 ? false : true);
134
121
}
135
122
136
-
137
- // Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7
123
+ // Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7
138
124
// 8 9 a b c d e f A B C D E F.
139
125
inline bool isHexadecimalDigit (int c )
140
126
{
141
- return ( isxdigit (c ) == 0 ? false : true);
127
+ return (isxdigit (c ) == 0 ? false : true);
142
128
}
143
129
144
-
145
- // Converts c to a 7-bit unsigned char value that fits into the
130
+ // Converts c to a 7-bit unsigned char value that fits into the
146
131
// ASCII character set, by clearing the high-order bits.
147
132
inline int toAscii (int c )
148
133
{
149
- return toascii (c );
134
+ return toascii (c );
150
135
}
151
136
152
-
153
137
// Warning:
154
- // Many people will be unhappy if you use this function.
155
- // This function will convert accented letters into random
138
+ // Many people will be unhappy if you use this function.
139
+ // This function will convert accented letters into random
156
140
// characters.
157
141
158
142
// Converts the letter c to lower case, if possible.
159
143
inline int toLowerCase (int c )
160
144
{
161
- return tolower (c );
145
+ return tolower (c );
162
146
}
163
147
164
-
165
148
// Converts the letter c to upper case, if possible.
166
149
inline int toUpperCase (int c )
167
150
{
168
- return toupper (c );
151
+ return toupper (c );
169
152
}
170
153
171
154
#endif
0 commit comments