sanguino/cores/arduino/WCharacter.h

Fri, 17 Nov 2017 10:13:31 +0100

author
mdd
date
Fri, 17 Nov 2017 10:13:31 +0100
changeset 3
770b218a4931
parent 2
b373b0288715
permissions
-rw-r--r--

proper configuration, homing and planner optimization

2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
1 /*
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
2 WCharacter.h - Character utility functions for Wiring & Arduino
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
3 Copyright (c) 2010 Hernando Barragan. All right reserved.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
4
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
7 License as published by the Free Software Foundation; either
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
9
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
13 Lesser General Public License for more details.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
14
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
18 */
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
19
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
20 #ifndef Character_h
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
21 #define Character_h
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
22
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
23 #include <ctype.h>
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
24
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
25 // WCharacter.h prototypes
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
26 inline boolean isAlphaNumeric(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
27 inline boolean isAlpha(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
28 inline boolean isAscii(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
29 inline boolean isWhitespace(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
30 inline boolean isControl(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
31 inline boolean isDigit(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
32 inline boolean isGraph(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
33 inline boolean isLowerCase(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
34 inline boolean isPrintable(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
35 inline boolean isPunct(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
36 inline boolean isSpace(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
37 inline boolean isUpperCase(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
38 inline boolean isHexadecimalDigit(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
39 inline int toAscii(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
40 inline int toLowerCase(int c) __attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
41 inline int toUpperCase(int c)__attribute__((always_inline));
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
42
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
43
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
44 // Checks for an alphanumeric character.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
45 // It is equivalent to (isalpha(c) || isdigit(c)).
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
46 inline boolean isAlphaNumeric(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
47 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
48 return ( isalnum(c) == 0 ? false : true);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
49 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
50
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
51
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
52 // Checks for an alphabetic character.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
53 // It is equivalent to (isupper(c) || islower(c)).
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
54 inline boolean isAlpha(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
55 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
56 return ( isalpha(c) == 0 ? false : true);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
57 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
58
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
59
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
60 // Checks whether c is a 7-bit unsigned char value
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
61 // that fits into the ASCII character set.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
62 inline boolean isAscii(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
63 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
64 return ( isascii (c) == 0 ? false : true);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
65 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
66
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
67
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
68 // Checks for a blank character, that is, a space or a tab.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
69 inline boolean isWhitespace(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
70 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
71 return ( isblank (c) == 0 ? false : true);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
72 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
73
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
74
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
75 // Checks for a control character.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
76 inline boolean isControl(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
77 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
78 return ( iscntrl (c) == 0 ? false : true);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
79 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
80
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
81
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
82 // Checks for a digit (0 through 9).
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
83 inline boolean isDigit(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
84 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
85 return ( isdigit (c) == 0 ? false : true);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
86 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
87
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
88
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
89 // Checks for any printable character except space.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
90 inline boolean isGraph(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
91 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
92 return ( isgraph (c) == 0 ? false : true);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
93 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
94
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
95
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
96 // Checks for a lower-case character.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
97 inline boolean isLowerCase(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
98 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
99 return (islower (c) == 0 ? false : true);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
100 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
101
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
102
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
103 // Checks for any printable character including space.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
104 inline boolean isPrintable(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
105 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
106 return ( isprint (c) == 0 ? false : true);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
107 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
108
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
109
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
110 // Checks for any printable character which is not a space
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
111 // or an alphanumeric character.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
112 inline boolean isPunct(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
113 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
114 return ( ispunct (c) == 0 ? false : true);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
115 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
116
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
117
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
118 // Checks for white-space characters. For the avr-libc library,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
119 // these are: space, formfeed ('\f'), newline ('\n'), carriage
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
120 // return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
121 inline boolean isSpace(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
122 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
123 return ( isspace (c) == 0 ? false : true);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
124 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
125
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
126
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
127 // Checks for an uppercase letter.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
128 inline boolean isUpperCase(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
129 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
130 return ( isupper (c) == 0 ? false : true);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
131 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
132
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
133
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
134 // Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
135 // 8 9 a b c d e f A B C D E F.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
136 inline boolean isHexadecimalDigit(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
137 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
138 return ( isxdigit (c) == 0 ? false : true);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
139 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
140
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
141
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
142 // Converts c to a 7-bit unsigned char value that fits into the
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
143 // ASCII character set, by clearing the high-order bits.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
144 inline int toAscii(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
145 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
146 return toascii (c);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
147 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
148
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
149
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
150 // Warning:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
151 // Many people will be unhappy if you use this function.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
152 // This function will convert accented letters into random
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
153 // characters.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
154
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
155 // Converts the letter c to lower case, if possible.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
156 inline int toLowerCase(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
157 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
158 return tolower (c);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
159 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
160
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
161
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
162 // Converts the letter c to upper case, if possible.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
163 inline int toUpperCase(int c)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
164 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
165 return toupper (c);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
166 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
167
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
168 #endif

mercurial