Skip to content

Commit 7c27b0d

Browse files
authored
Add WCharacter support (#100)
thanks!
1 parent 660418c commit 7c27b0d

File tree

2 files changed

+165
-0
lines changed

2 files changed

+165
-0
lines changed

cores/arduino/Arduino.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ void yield(void);
4949
} // extern "C"
5050
#endif // __cplusplus
5151

52+
#ifdef __cplusplus
53+
# include "WCharacter.h"
54+
# include "WString.h"
55+
# include "WMath.h"
56+
//# include <Tone.h>
57+
# include <HardwareSerial.h>
58+
#endif
59+
5260
// Include pins variant
5361
#include "pins_arduino.h"
5462

cores/arduino/WCharacter.h

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

0 commit comments

Comments
 (0)