Skip to content

Commit 083c8cd

Browse files
committed
Change inline functions to macros in WCharacter.h
1 parent 8ad0c60 commit 083c8cd

File tree

1 file changed

+18
-165
lines changed

1 file changed

+18
-165
lines changed

api/WCharacter.h

+18-165
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,21 @@
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
1+
#pragma once
222

233
#include <ctype.h>
244

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

0 commit comments

Comments
 (0)