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
1818 */
19-
20- #ifndef Character_h
21- #define Character_h
19+ #ifndef CHARACTER_H
20+ #define CHARACTER_H
2221
2322#include <ctype.h>
2423
@@ -41,131 +40,115 @@ inline bool isUpperCase(int c) __attribute__((always_inline));
4140inline bool isHexadecimalDigit (int c ) __attribute__((always_inline ));
4241inline int toAscii (int c ) __attribute__((always_inline ));
4342inline 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 ));
4644
47- // Checks for an alphanumeric character.
45+ // Checks for an alphanumeric character.
4846// It is equivalent to (isalpha(c) || isdigit(c)).
49- inline bool isAlphaNumeric (int c )
47+ inline bool isAlphaNumeric (int c )
5048{
51- return ( isalnum (c ) == 0 ? false : true);
49+ return (isalnum (c ) == 0 ? false : true);
5250}
5351
54-
55- // Checks for an alphabetic character.
52+ // Checks for an alphabetic character.
5653// It is equivalent to (isupper(c) || islower(c)).
5754inline bool isAlpha (int c )
5855{
59- return ( isalpha (c ) == 0 ? false : true);
56+ return (isalpha (c ) == 0 ? false : true);
6057}
6158
62-
63- // Checks whether c is a 7-bit unsigned char value
59+ // Checks whether c is a 7-bit unsigned char value
6460// that fits into the ASCII character set.
6561inline bool isAscii (int c )
6662{
67- return ( isascii (c ) == 0 ? false : true);
63+ return (isascii (c ) == 0 ? false : true);
6864}
6965
70-
7166// Checks for a blank character, that is, a space or a tab.
7267inline bool isWhitespace (int c )
7368{
74- return ( isblank (c ) == 0 ? false : true);
69+ return (isblank (c ) == 0 ? false : true);
7570}
7671
77-
7872// Checks for a control character.
7973inline bool isControl (int c )
8074{
81- return ( iscntrl (c ) == 0 ? false : true);
75+ return (iscntrl (c ) == 0 ? false : true);
8276}
8377
84-
8578// Checks for a digit (0 through 9).
8679inline bool isDigit (int c )
8780{
88- return ( isdigit (c ) == 0 ? false : true);
81+ return (isdigit (c ) == 0 ? false : true);
8982}
9083
91-
9284// Checks for any printable character except space.
9385inline bool isGraph (int c )
9486{
95- return ( isgraph (c ) == 0 ? false : true);
87+ return (isgraph (c ) == 0 ? false : true);
9688}
9789
98-
9990// Checks for a lower-case character.
10091inline bool isLowerCase (int c )
10192{
102- return (islower (c ) == 0 ? false : true);
93+ return (islower (c ) == 0 ? false : true);
10394}
10495
105-
10696// Checks for any printable character including space.
10797inline bool isPrintable (int c )
10898{
109- return ( isprint (c ) == 0 ? false : true);
99+ return (isprint (c ) == 0 ? false : true);
110100}
111101
112-
113- // Checks for any printable character which is not a space
102+ // Checks for any printable character which is not a space
114103// or an alphanumeric character.
115104inline bool isPunct (int c )
116105{
117- return ( ispunct (c ) == 0 ? false : true);
106+ return (ispunct (c ) == 0 ? false : true);
118107}
119108
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
123111// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
124112inline bool isSpace (int c )
125113{
126- return ( isspace (c ) == 0 ? false : true);
114+ return (isspace (c ) == 0 ? false : true);
127115}
128116
129-
130117// Checks for an uppercase letter.
131118inline bool isUpperCase (int c )
132119{
133- return ( isupper (c ) == 0 ? false : true);
120+ return (isupper (c ) == 0 ? false : true);
134121}
135122
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
138124// 8 9 a b c d e f A B C D E F.
139125inline bool isHexadecimalDigit (int c )
140126{
141- return ( isxdigit (c ) == 0 ? false : true);
127+ return (isxdigit (c ) == 0 ? false : true);
142128}
143129
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
146131// ASCII character set, by clearing the high-order bits.
147132inline int toAscii (int c )
148133{
149- return toascii (c );
134+ return toascii (c );
150135}
151136
152-
153137// 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
156140// characters.
157141
158142// Converts the letter c to lower case, if possible.
159143inline int toLowerCase (int c )
160144{
161- return tolower (c );
145+ return tolower (c );
162146}
163147
164-
165148// Converts the letter c to upper case, if possible.
166149inline int toUpperCase (int c )
167150{
168- return toupper (c );
151+ return toupper (c );
169152}
170153
171154#endif
0 commit comments