Skip to content

Fixes implementation of __FlashStringHelper #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions cores/esp32/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,12 @@ size_t Print::printf(const char *format, ...)
}
return len;
}
/*
size_t Print::print(const __FlashStringHelper *ifsh) {
PGM_P p = reinterpret_cast<PGM_P>(ifsh);

size_t n = 0;
while (1) {
uint8_t c = pgm_read_byte(p++);
if (c == 0) break;
n += write(c);
}
return n;
size_t Print::print(const __FlashStringHelper *ifsh)
{
return print(reinterpret_cast<const char *>(ifsh));
}
*/

size_t Print::print(const String &s)
{
return write(s.c_str(), s.length());
Expand Down Expand Up @@ -140,14 +133,14 @@ size_t Print::print(double n, int digits)
{
return printFloat(n, digits);
}
/*

size_t Print::println(const __FlashStringHelper *ifsh)
{
size_t n = print(ifsh);
n += println();
return n;
}
*/

size_t Print::print(const Printable& x)
{
return x.printTo(*this);
Expand Down
4 changes: 2 additions & 2 deletions cores/esp32/Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Print
}

size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3)));
//size_t print(const __FlashStringHelper *);
size_t print(const __FlashStringHelper *);
size_t print(const String &);
size_t print(const char[]);
size_t print(char);
Expand All @@ -85,7 +85,7 @@ class Print
size_t print(const Printable&);
size_t print(struct tm * timeinfo, const char * format = NULL);

//size_t println(const __FlashStringHelper *);
size_t println(const __FlashStringHelper *);
size_t println(const String &s);
size_t println(const char[]);
size_t println(char);
Expand Down
46 changes: 15 additions & 31 deletions cores/esp32/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ String::String(const String &value)
init();
*this = value;
}
/*
String::String(const __FlashStringHelper *pstr) {
init();
*this = pstr; // see operator =
}
*/

#ifdef __GXX_EXPERIMENTAL_CXX0X__
String::String(String &&rval)
{
Expand Down Expand Up @@ -200,17 +195,12 @@ String & String::copy(const char *cstr, unsigned int length)
strcpy(buffer, cstr);
return *this;
}
/*
String & String::copy(const __FlashStringHelper *pstr, unsigned int length) {
if (!reserve(length)) {
invalidate();
return *this;
}
len = length;
strcpy_P(buffer, (PGM_P)pstr);
return *this;

String & String::copy(const __FlashStringHelper *pstr, unsigned int length)
{
return copy(reinterpret_cast<const char *>(pstr), length);
}
*/

#ifdef __GXX_EXPERIMENTAL_CXX0X__
void String::move(String &rhs)
{
Expand Down Expand Up @@ -276,15 +266,15 @@ String & String::operator =(const char *cstr)

return *this;
}
/*

String & String::operator = (const __FlashStringHelper *pstr)
{
if (pstr) copy(pstr, strlen_P((PGM_P)pstr));
else invalidate();

return *this;
}
*/

// /*********************************************/
// /* concat */
// /*********************************************/
Expand Down Expand Up @@ -375,18 +365,12 @@ unsigned char String::concat(double num)
char* string = dtostrf(num, 4, 2, buf);
return concat(string, strlen(string));
}
/*
unsigned char String::concat(const __FlashStringHelper * str) {
if (!str) return 0;
int length = strlen_P((PGM_P)str);
if (length == 0) return 1;
unsigned int newlen = len + length;
if (!reserve(newlen)) return 0;
strcpy_P(buffer + len, (PGM_P)str);
len = newlen;
return 1;

unsigned char String::concat(const __FlashStringHelper * str)
{
return concat(reinterpret_cast<const char *>(str));
}
*/

/*********************************************/
/* Concatenate */
/*********************************************/
Expand Down Expand Up @@ -480,14 +464,14 @@ StringSumHelper & operator +(const StringSumHelper &lhs, double num)
}
return a;
}
/*

StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs)
{
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
if (!a.concat(rhs)) a.invalidate();
return a;
}
*/

// /*********************************************/
// /* Comparison */
// /*********************************************/
Expand Down
22 changes: 12 additions & 10 deletions cores/esp32/WString.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class StringSumHelper;

// an abstract class used as a means to proide a unique pointer type
// but really has no body
//class __FlashStringHelper;
class __FlashStringHelper;
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

// The string class
class String
Expand All @@ -55,7 +56,7 @@ class String
// be false).
String(const char *cstr = "");
String(const String &str);
//String(const __FlashStringHelper *str);
String(const __FlashStringHelper *str) : String(reinterpret_cast<const char *>(str)) {};
#ifdef __GXX_EXPERIMENTAL_CXX0X__
String(String &&rval);
String(StringSumHelper &&rval);
Expand Down Expand Up @@ -89,7 +90,7 @@ class String
// marked as invalid ("if (s)" will be false).
String & operator =(const String &rhs);
String & operator =(const char *cstr);
//String & operator = (const __FlashStringHelper *str);
String & operator = (const __FlashStringHelper *str);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
String & operator =(String &&rval);
String & operator =(StringSumHelper &&rval);
Expand All @@ -110,7 +111,7 @@ class String
unsigned char concat(unsigned long num);
unsigned char concat(float num);
unsigned char concat(double num);
//unsigned char concat(const __FlashStringHelper * str);
unsigned char concat(const __FlashStringHelper * str);

// if there's not enough memory for the concatenated value, the string
// will be left unchanged (but this isn't signalled in any way)
Expand Down Expand Up @@ -164,10 +165,11 @@ class String
concat(num);
return (*this);
}
//String & operator += (const __FlashStringHelper *str){
// concat(str);
// return (*this);
//}
String & operator += (const __FlashStringHelper *str)
{
concat(str);
return (*this);
}

friend StringSumHelper & operator +(const StringSumHelper &lhs, const String &rhs);
friend StringSumHelper & operator +(const StringSumHelper &lhs, const char *cstr);
Expand All @@ -179,7 +181,7 @@ class String
friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long num);
friend StringSumHelper & operator +(const StringSumHelper &lhs, float num);
friend StringSumHelper & operator +(const StringSumHelper &lhs, double num);
//friend StringSumHelper & operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs);
friend StringSumHelper & operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs);

// comparison (only works w/ Strings and "strings")
operator StringIfHelperType() const
Expand Down Expand Up @@ -270,7 +272,7 @@ class String

// copy and move
String & copy(const char *cstr, unsigned int length);
//String & copy(const __FlashStringHelper *pstr, unsigned int length);
String & copy(const __FlashStringHelper *pstr, unsigned int length);
#ifdef __GXX_EXPERIMENTAL_CXX0X__
void move(String &rhs);
#endif
Expand Down
3 changes: 0 additions & 3 deletions cores/esp32/pgmspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@ typedef unsigned short prog_uint16_t;
typedef long prog_int32_t;
typedef unsigned long prog_uint32_t;

typedef char __FlashStringHelper;

#define SIZE_IRRELEVANT 0x7fffffff

#define PROGMEM
#define PGM_P const char *
#define PGM_VOID_P const void *
#define FPSTR(p) ((const char *)(p))
#define PSTR(s) (s)
#define F(s) (s)
#define _SFR_BYTE(n) (n)

#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
Expand Down