PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Dependents:   Sensitive

Fork of PokittoLib by Jonne Valola

Committer:
Pokitto
Date:
Thu Oct 12 10:36:40 2017 +0000
Revision:
9:754a7af30890
Fake Arduino lib added

Who changed what in which revision?

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