Add FlashString abstract class
Add FlashString abstract class to support extension of String and Print methods to core specific program memory implementation. The FlashString abstract class completely eliminates the dependency on the file pgmspace.h. ArduinoCore-API should never include any references to a specific implementation (e.g. AVR).
An example implementation is shown below, tested on a SAMD21 core. I have not had a chance to implement / test on an AVR-based Arduino, but should be easily implemented at avr core level.
class FlashStringTest : public FlashString
{
public:
FlashStringTest(uintptr_t address): _address(address) {}
String toString() const;
size_t printTo(Print& p) const;
protected:
uintptr_t _address;
};
String FlashStringTest::toString() const
{
return String((const char *)_address);
}
size_t FlashStringTest::printTo(Print& p) const
{
size_t n = 0;
const char* str = (const char*)_address;
while (1) {
char c = *str++;
if (c == 0) break;
if (p.print(c)) n++;
else break;
}
return n;
}
#ifdef F
#undef F
#endif
#define F(string_literal) (FlashStringTest((uintptr_t)(string_literal)))
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.
Is your intention to break all libraries which have used __FlashStringHelper?