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