31
31
#include < ctype.h>
32
32
33
33
34
- // an abstract class used as a means to proide a unique pointer type
35
- // but really has no body
34
+ // A pure abstract class forward used as a means to proide a unique pointer type
35
+ // but really is never defined.
36
36
class __FlashStringHelper ;
37
- #define FPSTR (pstr_pointer ) (reinterpret_cast < const __FlashStringHelper *>( pstr_pointer) )
38
- #define F (string_literal ) (FPSTR(PSTR( string_literal)) )
37
+ #define FPSTR (pstr_pointer ) (pstr_pointer)
38
+ #define F (string_literal ) (string_literal)
39
39
40
40
// An inherited class for holding the result of a concatenation. These
41
41
// result objects are assumed to be writable by subsequent concatenations.
@@ -59,10 +59,10 @@ class String {
59
59
String (const char *cstr = " " );
60
60
String (const char *cstr, unsigned int length);
61
61
#ifdef __GXX_EXPERIMENTAL_CXX0X__
62
- String (const uint8_t *cstr, unsigned int length) : String(( const char *) cstr, length) {}
62
+ String (const uint8_t *cstr, unsigned int length) : String(reinterpret_cast < const char *>( cstr) , length) {}
63
63
#endif
64
64
String (const String &str);
65
- String (const __FlashStringHelper *str);
65
+ String (const __FlashStringHelper *str) : String( reinterpret_cast < const char *>(str)) {}
66
66
#ifdef __GXX_EXPERIMENTAL_CXX0X__
67
67
String (String &&rval);
68
68
String (StringSumHelper &&rval);
@@ -103,7 +103,7 @@ class String {
103
103
// marked as invalid ("if (s)" will be false).
104
104
String & operator =(const String &rhs);
105
105
String & operator =(const char *cstr);
106
- String & operator = (const __FlashStringHelper *str);
106
+ String & operator = (const __FlashStringHelper *str) { return * this = reinterpret_cast < const char *>(str);}
107
107
#ifdef __GXX_EXPERIMENTAL_CXX0X__
108
108
String & operator =(String &&rval);
109
109
String & operator =(StringSumHelper &&rval);
@@ -117,7 +117,7 @@ class String {
117
117
bool concat (const String &str);
118
118
bool concat (const char *cstr);
119
119
bool concat (const char *cstr, unsigned int length);
120
- bool concat (const uint8_t *cstr, unsigned int length) {return concat (( const char *) cstr, length);}
120
+ bool concat (const uint8_t *cstr, unsigned int length) {return concat (reinterpret_cast < const char *>( cstr) , length);}
121
121
bool concat (char c);
122
122
bool concat (unsigned char c);
123
123
bool concat (int num);
@@ -128,7 +128,7 @@ class String {
128
128
bool concat (double num);
129
129
bool concat (long long num);
130
130
bool concat (unsigned long long num);
131
- bool concat (const __FlashStringHelper * str);
131
+ bool concat (const __FlashStringHelper * str) { return concat ( reinterpret_cast < const char *>(str));}
132
132
133
133
// if there's not enough memory for the concatenated value, the string
134
134
// will be left unchanged (but this isn't signalled in any way)
@@ -180,10 +180,7 @@ class String {
180
180
concat (num);
181
181
return (*this );
182
182
}
183
- String & operator += (const __FlashStringHelper *str){
184
- concat (str);
185
- return (*this );
186
- }
183
+ String & operator += (const __FlashStringHelper *str) {return *this += reinterpret_cast <const char *>(str);}
187
184
188
185
friend StringSumHelper & operator +(const StringSumHelper &lhs, const String &rhs);
189
186
friend StringSumHelper & operator +(const StringSumHelper &lhs, const char *cstr);
@@ -195,7 +192,6 @@ class String {
195
192
friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long num);
196
193
friend StringSumHelper & operator +(const StringSumHelper &lhs, float num);
197
194
friend StringSumHelper & operator +(const StringSumHelper &lhs, double num);
198
- friend StringSumHelper & operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs);
199
195
friend StringSumHelper & operator +(const StringSumHelper &lhs, long long num);
200
196
friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long long num);
201
197
@@ -229,15 +225,15 @@ class String {
229
225
return this ->startsWith (String (prefix));
230
226
}
231
227
bool startsWith (const __FlashStringHelper *prefix) const {
232
- return this ->startsWith (String (prefix));
228
+ return this ->startsWith (reinterpret_cast < const char *> (prefix));
233
229
}
234
230
bool startsWith (const String &prefix, unsigned int offset) const ;
235
231
bool endsWith (const String &suffix) const ;
236
232
bool endsWith (const char *suffix) const {
237
233
return this ->endsWith (String (suffix));
238
234
}
239
235
bool endsWith (const __FlashStringHelper * suffix) const {
240
- return this ->endsWith (String (suffix));
236
+ return this ->endsWith (reinterpret_cast < const char *> (suffix));
241
237
}
242
238
243
239
// character access
@@ -276,16 +272,16 @@ class String {
276
272
this ->replace (String (find), replace);
277
273
}
278
274
void replace (const __FlashStringHelper *find, const String &replace) {
279
- this ->replace (String (find), replace);
275
+ this ->replace (reinterpret_cast < const char *> (find), replace);
280
276
}
281
277
void replace (const char *find, const char *replace) {
282
278
this ->replace (String (find), String (replace));
283
279
}
284
280
void replace (const __FlashStringHelper *find, const char *replace) {
285
- this ->replace (String (find), String (replace));
281
+ this ->replace (reinterpret_cast < const char *> (find), String (replace));
286
282
}
287
283
void replace (const __FlashStringHelper *find, const __FlashStringHelper *replace) {
288
- this ->replace (String (find), String (replace));
284
+ this ->replace (reinterpret_cast < const char *> (find), reinterpret_cast < const char *> (replace));
289
285
}
290
286
void remove (unsigned int index);
291
287
void remove (unsigned int index, unsigned int count);
@@ -340,7 +336,7 @@ class String {
340
336
inline void setCapacity (int cap) { if (!isSSO ()) ptr.cap = cap; }
341
337
inline void setBuffer (char *buff) { if (!isSSO ()) ptr.buff = buff; }
342
338
// Buffer accessor functions
343
- inline const char *buffer () const { return ( const char *) (isSSO () ? sso.buff : ptr.buff ); }
339
+ inline const char *buffer () const { return reinterpret_cast < const char *> (isSSO () ? sso.buff : ptr.buff ); }
344
340
inline char *wbuffer () const { return isSSO () ? const_cast <char *>(sso.buff ) : ptr.buff ; } // Writable version of buffer
345
341
346
342
protected:
@@ -350,7 +346,9 @@ class String {
350
346
351
347
// copy and move
352
348
String & copy (const char *cstr, unsigned int length);
353
- String & copy (const __FlashStringHelper *pstr, unsigned int length);
349
+ String & copy (const __FlashStringHelper *pstr, unsigned int length) {
350
+ return copy (reinterpret_cast <const char *>(pstr), length);
351
+ }
354
352
#ifdef __GXX_EXPERIMENTAL_CXX0X__
355
353
void move (String &rhs);
356
354
#endif
@@ -395,6 +393,10 @@ class StringSumHelper: public String {
395
393
String (num) {
396
394
}
397
395
};
396
+
397
+ inline StringSumHelper & operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs) {
398
+ return lhs + reinterpret_cast <const char *>(rhs);
399
+ }
398
400
399
401
extern const String emptyString;
400
402
0 commit comments