Skip to content

Commit e9e9048

Browse files
Added new file WCharacter.h, and updated String files to add missing Arduino API functionality
1 parent 76157ad commit e9e9048

4 files changed

Lines changed: 194 additions & 14 deletions

File tree

STM32F1/cores/maple/WCharacter.h

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

STM32F1/cores/maple/WString.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ String::String(const __FlashStringHelper *pstr)
4545
*this = pstr;
4646
}
4747

48-
#ifdef __GXX_EXPERIMENTAL_CXX0X__
48+
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
4949
String::String(String &&rval)
5050
{
5151
init();
@@ -191,7 +191,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length)
191191
return *this;
192192
}
193193

194-
#ifdef __GXX_EXPERIMENTAL_CXX0X__
194+
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
195195
void String::move(String &rhs)
196196
{
197197
if (buffer) {
@@ -223,7 +223,7 @@ String & String::operator = (const String &rhs)
223223
return *this;
224224
}
225225

226-
#ifdef __GXX_EXPERIMENTAL_CXX0X__
226+
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
227227
String & String::operator = (String &&rval)
228228
{
229229
if (this != &rval) move(rval);
@@ -621,7 +621,7 @@ String String::substring(unsigned int left, unsigned int right) const
621621
left = temp;
622622
}
623623
String out;
624-
if (left > len) return out;
624+
if (left >= len) return out;
625625
if (right > len) right = len;
626626
char temp = buffer[right]; // save the replaced character
627627
buffer[right] = '\0';
@@ -686,15 +686,16 @@ void String::replace(const String& find, const String& replace)
686686
}
687687

688688
void String::remove(unsigned int index){
689-
if (index >= len) { return; }
690-
int count = len - index;
691-
remove(index, count);
689+
// Pass the biggest integer as the count. The remove method
690+
// below will take care of truncating it at the end of the
691+
// string.
692+
remove(index, (unsigned int)-1);
692693
}
693694

694695
void String::remove(unsigned int index, unsigned int count){
695696
if (index >= len) { return; }
696697
if (count <= 0) { return; }
697-
if (index + count > len) { count = len - index; }
698+
if (count > len - index) { count = len - index; }
698699
char *writeTo = buffer + index;
699700
len = len - count;
700701
strncpy(writeTo, buffer + index + count,len - index);

STM32F1/cores/maple/WString.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class String
5959
String(const char *cstr = "");
6060
String(const String &str);
6161
String(const __FlashStringHelper *str);
62-
#ifdef __GXX_EXPERIMENTAL_CXX0X__
62+
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
6363
String(String &&rval);
6464
String(StringSumHelper &&rval);
6565
#endif
@@ -86,7 +86,7 @@ class String
8686
String & operator = (const String &rhs);
8787
String & operator = (const char *cstr);
8888
String & operator = (const __FlashStringHelper *str);
89-
#ifdef __GXX_EXPERIMENTAL_CXX0X__
89+
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
9090
String & operator = (String &&rval);
9191
String & operator = (StringSumHelper &&rval);
9292
#endif
@@ -200,7 +200,7 @@ class String
200200
// copy and move
201201
String & copy(const char *cstr, unsigned int length);
202202
String & copy(const __FlashStringHelper *pstr, unsigned int length);
203-
#ifdef __GXX_EXPERIMENTAL_CXX0X__
203+
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
204204
void move(String &rhs);
205205
#endif
206206
};

STM32F1/cores/maple/wirish.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444

4545
#include <string.h>
46+
4647
#include <WString.h>
4748
#include <avr/dtostrf.h>
4849
#include <avr/pgmspace.h>
@@ -74,9 +75,7 @@
7475

7576
#include <stdint.h>
7677

77-
78-
79-
78+
#include <WCharacter.h>
8079

8180
typedef unsigned int word;
8281
// typedef uint16 word;// definition from Arduino website, now appears to be incorrect for 32 bit devices

0 commit comments

Comments
 (0)