3131#include < ctype.h>
3232
3333
34- // A pure abstract class forward used as a means to proide a unique pointer type
35- // but really is never defined.
34+ // an abstract class used as a means to proide a unique pointer type
35+ // but really has no body
3636class __FlashStringHelper ;
37- #define FPSTR (pstr_pointer ) (pstr_pointer)
38- #define F (string_literal ) (string_literal)
37+ #define FPSTR (pstr_pointer ) (reinterpret_cast < const __FlashStringHelper *>( pstr_pointer) )
38+ #define F (string_literal ) (FPSTR(PSTR( string_literal)) )
3939
4040// An inherited class for holding the result of a concatenation. These
4141// result objects are assumed to be writable by subsequent concatenations.
@@ -59,10 +59,10 @@ class String {
5959 String (const char *cstr = " " );
6060 String (const char *cstr, unsigned int length);
6161#ifdef __GXX_EXPERIMENTAL_CXX0X__
62- String (const uint8_t *cstr, unsigned int length) : String(reinterpret_cast < const char *>(cstr) , length) {}
62+ String (const uint8_t *cstr, unsigned int length) : String(( const char *)cstr , length) {}
6363#endif
6464 String (const String &str);
65- String (const __FlashStringHelper *str) : String( reinterpret_cast < const char *>(str)) {}
65+ String (const __FlashStringHelper *str);
6666#ifdef __GXX_EXPERIMENTAL_CXX0X__
6767 String (String &&rval);
6868 String (StringSumHelper &&rval);
@@ -103,7 +103,7 @@ class String {
103103 // marked as invalid ("if (s)" will be false).
104104 String & operator =(const String &rhs);
105105 String & operator =(const char *cstr);
106- String & operator = (const __FlashStringHelper *str) { return * this = reinterpret_cast < const char *>(str);}
106+ String & operator = (const __FlashStringHelper *str);
107107#ifdef __GXX_EXPERIMENTAL_CXX0X__
108108 String & operator =(String &&rval);
109109 String & operator =(StringSumHelper &&rval);
@@ -117,7 +117,7 @@ class String {
117117 bool concat (const String &str);
118118 bool concat (const char *cstr);
119119 bool concat (const char *cstr, unsigned int length);
120- bool concat (const uint8_t *cstr, unsigned int length) {return concat (reinterpret_cast < const char *>(cstr) , length);}
120+ bool concat (const uint8_t *cstr, unsigned int length) {return concat (( const char *)cstr , length);}
121121 bool concat (char c);
122122 bool concat (unsigned char c);
123123 bool concat (int num);
@@ -128,7 +128,7 @@ class String {
128128 bool concat (double num);
129129 bool concat (long long num);
130130 bool concat (unsigned long long num);
131- bool concat (const __FlashStringHelper * str) { return concat ( reinterpret_cast < const char *>(str));}
131+ bool concat (const __FlashStringHelper * str);
132132
133133 // if there's not enough memory for the concatenated value, the string
134134 // will be left unchanged (but this isn't signalled in any way)
@@ -180,7 +180,10 @@ class String {
180180 concat (num);
181181 return (*this );
182182 }
183- String & operator += (const __FlashStringHelper *str) {return *this += reinterpret_cast <const char *>(str);}
183+ String & operator += (const __FlashStringHelper *str){
184+ concat (str);
185+ return (*this );
186+ }
184187
185188 friend StringSumHelper & operator +(const StringSumHelper &lhs, const String &rhs);
186189 friend StringSumHelper & operator +(const StringSumHelper &lhs, const char *cstr);
@@ -192,6 +195,7 @@ class String {
192195 friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long num);
193196 friend StringSumHelper & operator +(const StringSumHelper &lhs, float num);
194197 friend StringSumHelper & operator +(const StringSumHelper &lhs, double num);
198+ friend StringSumHelper & operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs);
195199 friend StringSumHelper & operator +(const StringSumHelper &lhs, long long num);
196200 friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long long num);
197201
@@ -225,15 +229,15 @@ class String {
225229 return this ->startsWith (String (prefix));
226230 }
227231 bool startsWith (const __FlashStringHelper *prefix) const {
228- return this ->startsWith (reinterpret_cast < const char *> (prefix));
232+ return this ->startsWith (String (prefix));
229233 }
230234 bool startsWith (const String &prefix, unsigned int offset) const ;
231235 bool endsWith (const String &suffix) const ;
232236 bool endsWith (const char *suffix) const {
233237 return this ->endsWith (String (suffix));
234238 }
235239 bool endsWith (const __FlashStringHelper * suffix) const {
236- return this ->endsWith (reinterpret_cast < const char *> (suffix));
240+ return this ->endsWith (String (suffix));
237241 }
238242
239243 // character access
@@ -272,16 +276,16 @@ class String {
272276 this ->replace (String (find), replace);
273277 }
274278 void replace (const __FlashStringHelper *find, const String &replace) {
275- this ->replace (reinterpret_cast < const char *> (find), replace);
279+ this ->replace (String (find), replace);
276280 }
277281 void replace (const char *find, const char *replace) {
278282 this ->replace (String (find), String (replace));
279283 }
280284 void replace (const __FlashStringHelper *find, const char *replace) {
281- this ->replace (reinterpret_cast < const char *> (find), String (replace));
285+ this ->replace (String (find), String (replace));
282286 }
283287 void replace (const __FlashStringHelper *find, const __FlashStringHelper *replace) {
284- this ->replace (reinterpret_cast < const char *> (find), reinterpret_cast < const char *> (replace));
288+ this ->replace (String (find), String (replace));
285289 }
286290 void remove (unsigned int index);
287291 void remove (unsigned int index, unsigned int count);
@@ -336,7 +340,7 @@ class String {
336340 inline void setCapacity (int cap) { if (!isSSO ()) ptr.cap = cap; }
337341 inline void setBuffer (char *buff) { if (!isSSO ()) ptr.buff = buff; }
338342 // Buffer accessor functions
339- inline const char *buffer () const { return reinterpret_cast < const char *> (isSSO () ? sso.buff : ptr.buff ); }
343+ inline const char *buffer () const { return ( const char *) (isSSO () ? sso.buff : ptr.buff ); }
340344 inline char *wbuffer () const { return isSSO () ? const_cast <char *>(sso.buff ) : ptr.buff ; } // Writable version of buffer
341345
342346 protected:
@@ -346,9 +350,7 @@ class String {
346350
347351 // copy and move
348352 String & copy (const char *cstr, unsigned int length);
349- String & copy (const __FlashStringHelper *pstr, unsigned int length) {
350- return copy (reinterpret_cast <const char *>(pstr), length);
351- }
353+ String & copy (const __FlashStringHelper *pstr, unsigned int length);
352354#ifdef __GXX_EXPERIMENTAL_CXX0X__
353355 void move (String &rhs);
354356#endif
@@ -393,10 +395,6 @@ class StringSumHelper: public String {
393395 String (num) {
394396 }
395397};
396-
397- inline StringSumHelper & operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs) {
398- return lhs + reinterpret_cast <const char *>(rhs);
399- }
400398
401399extern const String emptyString;
402400
0 commit comments