aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/WString.cpp
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2013-06-06 15:41:23 +0200
committerCristian Maglie <c.maglie@bug.st>2013-06-06 16:33:20 +0200
commitdb286ac0c1305f9f6338acc37da7c24ebdc9243b (patch)
tree932ca169a6a9b4a58639f76088c0b5331a8256d6 /cores/arduino/WString.cpp
parent2719777a48418210563bf58199331eefe24969af (diff)
Added support for Flash string on String class.
Diffstat (limited to 'cores/arduino/WString.cpp')
-rw-r--r--cores/arduino/WString.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp
index 77bdd8a..5951a64 100644
--- a/cores/arduino/WString.cpp
+++ b/cores/arduino/WString.cpp
@@ -38,6 +38,12 @@ String::String(const String &value)
*this = value;
}
+String::String(const __FlashStringHelper *pstr)
+{
+ init();
+ *this = pstr;
+}
+
#ifdef __GXX_EXPERIMENTAL_CXX0X__
String::String(String &&rval)
{
@@ -160,6 +166,17 @@ String & String::copy(const char *cstr, unsigned int length)
return *this;
}
+String & String::copy(const __FlashStringHelper *pstr, unsigned int length)
+{
+ if (!reserve(length)) {
+ invalidate();
+ return *this;
+ }
+ len = length;
+ strcpy_P(buffer, (const prog_char *)pstr);
+ return *this;
+}
+
#ifdef __GXX_EXPERIMENTAL_CXX0X__
void String::move(String &rhs)
{
@@ -214,6 +231,14 @@ String & String::operator = (const char *cstr)
return *this;
}
+String & String::operator = (const __FlashStringHelper *pstr)
+{
+ if (pstr) copy(pstr, strlen_P((const prog_char *)pstr));
+ else invalidate();
+
+ return *this;
+}
+
/*********************************************/
/* concat */
/*********************************************/
@@ -283,6 +308,18 @@ unsigned char String::concat(unsigned long num)
return concat(buf, strlen(buf));
}
+unsigned char String::concat(const __FlashStringHelper * str)
+{
+ if (!str) return 0;
+ int length = strlen_P((const char *) str);
+ if (length == 0) return 1;
+ unsigned int newlen = len + length;
+ if (!reserve(newlen)) return 0;
+ strcpy_P(buffer + len, (const char *) str);
+ len = newlen;
+ return 1;
+}
+
/*********************************************/
/* Concatenate */
/*********************************************/
@@ -343,6 +380,13 @@ StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long 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 */
/*********************************************/