26
26
#include < stdlib.h>
27
27
#include < string.h>
28
28
#include < ctype.h>
29
- #define PROGMEM
29
+ #include < pgmspace.h >
30
30
31
31
// An inherited class for holding the result of a concatenation. These
32
32
// result objects are assumed to be writable by subsequent concatenations.
33
33
class StringSumHelper ;
34
34
35
- typedef char * __FlashStringHelper;
36
- // #define F(str) []() -> const char * { static const char tmp[] ICACHE_RODATA_ATTR = str; return &tmp[0]; }()
37
- #define F (str ) str
35
+ // an abstract class used as a means to proide a unique pointer type
36
+ // but really has no body
37
+ class __FlashStringHelper ;
38
+ #define F (string_literal ) (reinterpret_cast <const __FlashStringHelper *>(PSTR(string_literal)))
39
+
38
40
39
41
// The string class
40
42
class String {
@@ -53,6 +55,7 @@ class String {
53
55
// be false).
54
56
String (const char *cstr = " " );
55
57
String (const String &str);
58
+ String (const __FlashStringHelper *str);
56
59
#ifdef __GXX_EXPERIMENTAL_CXX0X__
57
60
String (String &&rval);
58
61
String (StringSumHelper &&rval);
@@ -81,6 +84,7 @@ class String {
81
84
// marked as invalid ("if (s)" will be false).
82
85
String & operator =(const String &rhs);
83
86
String & operator =(const char *cstr);
87
+ String & operator = (const __FlashStringHelper *str);
84
88
#ifdef __GXX_EXPERIMENTAL_CXX0X__
85
89
String & operator =(String &&rval);
86
90
String & operator =(StringSumHelper &&rval);
@@ -101,6 +105,7 @@ class String {
101
105
unsigned char concat (unsigned long num);
102
106
unsigned char concat (float num);
103
107
unsigned char concat (double num);
108
+ unsigned char concat (const __FlashStringHelper * str);
104
109
105
110
// if there's not enough memory for the concatenated value, the string
106
111
// will be left unchanged (but this isn't signalled in any way)
@@ -144,6 +149,10 @@ class String {
144
149
concat (num);
145
150
return (*this );
146
151
}
152
+ String & operator += (const __FlashStringHelper *str){
153
+ concat (str);
154
+ return (*this );
155
+ }
147
156
148
157
friend StringSumHelper & operator +(const StringSumHelper &lhs, const String &rhs);
149
158
friend StringSumHelper & operator +(const StringSumHelper &lhs, const char *cstr);
@@ -155,6 +164,7 @@ class String {
155
164
friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long num);
156
165
friend StringSumHelper & operator +(const StringSumHelper &lhs, float num);
157
166
friend StringSumHelper & operator +(const StringSumHelper &lhs, double num);
167
+ friend StringSumHelper & operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs);
158
168
159
169
// comparison (only works w/ Strings and "strings")
160
170
operator StringIfHelperType () const {
@@ -237,6 +247,7 @@ class String {
237
247
238
248
// copy and move
239
249
String & copy (const char *cstr, unsigned int length);
250
+ String & copy (const __FlashStringHelper *pstr, unsigned int length);
240
251
#ifdef __GXX_EXPERIMENTAL_CXX0X__
241
252
void move (String &rhs);
242
253
#endif
0 commit comments