forked from espressif/arduino-esp32
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWCharacter.h
138 lines (114 loc) · 4.5 KB
/
WCharacter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
WCharacter.h - Character utility functions for Wiring & Arduino
Copyright (c) 2010 Hernando Barragan. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndefCharacter_h
#defineCharacter_h
#include<ctype.h>
#defineisascii(__c) ((unsigned)(__c) <= 0177)
#definetoascii(__c) ((__c) & 0177)
// WCharacter.h prototypes
inlinebooleanisAlphaNumeric(intc) __attribute__((always_inline));
inlinebooleanisAlpha(intc) __attribute__((always_inline));
inlinebooleanisAscii(intc) __attribute__((always_inline));
inlinebooleanisWhitespace(intc) __attribute__((always_inline));
inlinebooleanisControl(intc) __attribute__((always_inline));
inlinebooleanisDigit(intc) __attribute__((always_inline));
inlinebooleanisGraph(intc) __attribute__((always_inline));
inlinebooleanisLowerCase(intc) __attribute__((always_inline));
inlinebooleanisPrintable(intc) __attribute__((always_inline));
inlinebooleanisPunct(intc) __attribute__((always_inline));
inlinebooleanisSpace(intc) __attribute__((always_inline));
inlinebooleanisUpperCase(intc) __attribute__((always_inline));
inlinebooleanisHexadecimalDigit(intc) __attribute__((always_inline));
inlineinttoAscii(intc) __attribute__((always_inline));
inlineinttoLowerCase(intc) __attribute__((always_inline));
inlineinttoUpperCase(intc) __attribute__((always_inline));
// Checks for an alphanumeric character.
// It is equivalent to (isalpha(c) || isdigit(c)).
inlinebooleanisAlphaNumeric(intc) {
return (isalnum(c) ==0 ? false : true);
}
// Checks for an alphabetic character.
// It is equivalent to (isupper(c) || islower(c)).
inlinebooleanisAlpha(intc) {
return (isalpha(c) ==0 ? false : true);
}
// Checks whether c is a 7-bit unsigned char value
// that fits into the ASCII character set.
inlinebooleanisAscii(intc) {
return (isascii(c) ==0 ? false : true);
}
// Checks for a blank character, that is, a space or a tab.
inlinebooleanisWhitespace(intc) {
return (isblank(c) ==0 ? false : true);
}
// Checks for a control character.
inlinebooleanisControl(intc) {
return (iscntrl(c) ==0 ? false : true);
}
// Checks for a digit (0 through 9).
inlinebooleanisDigit(intc) {
return (isdigit(c) ==0 ? false : true);
}
// Checks for any printable character except space.
inlinebooleanisGraph(intc) {
return (isgraph(c) ==0 ? false : true);
}
// Checks for a lower-case character.
inlinebooleanisLowerCase(intc) {
return (islower(c) ==0 ? false : true);
}
// Checks for any printable character including space.
inlinebooleanisPrintable(intc) {
return (isprint(c) ==0 ? false : true);
}
// Checks for any printable character which is not a space
// or an alphanumeric character.
inlinebooleanisPunct(intc) {
return (ispunct(c) ==0 ? false : true);
}
// Checks for white-space characters. For the avr-libc library,
// these are: space, formfeed ('\f'), newline ('\n'), carriage
// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
inlinebooleanisSpace(intc) {
return (isspace(c) ==0 ? false : true);
}
// Checks for an uppercase letter.
inlinebooleanisUpperCase(intc) {
return (isupper(c) ==0 ? false : true);
}
// Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7
// 8 9 a b c d e f A B C D E F.
inlinebooleanisHexadecimalDigit(intc) {
return (isxdigit(c) ==0 ? false : true);
}
// Converts c to a 7-bit unsigned char value that fits into the
// ASCII character set, by clearing the high-order bits.
inlineinttoAscii(intc) {
returntoascii(c);
}
// Warning:
// Many people will be unhappy if you use this function.
// This function will convert accented letters into random
// characters.
// Converts the letter c to lower case, if possible.
inlineinttoLowerCase(intc) {
returntolower(c);
}
// Converts the letter c to upper case, if possible.
inlineinttoUpperCase(intc) {
returntoupper(c);
}
#endif