diff --git a/lib/ArduinoNative/src/WString.h b/lib/ArduinoNative/src/WString.h index 3ea925cc..184733e6 100644 --- a/lib/ArduinoNative/src/WString.h +++ b/lib/ArduinoNative/src/WString.h @@ -41,6 +41,10 @@ * Compile Switches *****************************************************************************/ +#ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING +#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 +#endif + /****************************************************************************** * Includes *****************************************************************************/ @@ -648,6 +652,29 @@ class String } } + bool concat(const String& s) + { + (void)this->operator+=(s); + return true; + } + + bool concat(const char* cstr) + { + if ((nullptr == cstr) || (0U == strlen(cstr))) + { + return false; + } + + (void)this->operator+=(cstr); + return true; + } + + bool concat(char c) + { + (void)this->operator+=(c); + return true; + } + private: size_t m_size; /**< String buffer size */ char* m_buffer; /**< String buffer */ diff --git a/test/test_WString/test_WString.cpp b/test/test_WString/test_WString.cpp index b8a25f4b..811a53a4 100644 --- a/test/test_WString/test_WString.cpp +++ b/test/test_WString/test_WString.cpp @@ -53,6 +53,7 @@ static void testWStringReplacement(void); static void testWStringAppend(void); +static void testWStringConcat(void); /****************************************************************************** * Local Variables @@ -88,6 +89,7 @@ extern int main(int argc, char** argv) RUN_TEST(testWStringReplacement); RUN_TEST(testWStringAppend); + RUN_TEST(testWStringConcat); return UNITY_END(); } @@ -154,11 +156,11 @@ static void testWStringReplacement(void) static void testWStringAppend(void) { String original = String("Im short"); - char classic[4]; - classic[0] = 'H'; - classic[1] = 'I'; - classic[2] = '!'; - classic[3] = '\0'; + char classic[4]; + classic[0] = 'H'; + classic[1] = 'I'; + classic[2] = '!'; + classic[3] = '\0'; original += String("- first amendment -"); original += classic; @@ -170,3 +172,26 @@ static void testWStringAppend(void) tester += "Im new"; TEST_ASSERT_EQUAL_STRING("Im new", tester.c_str()); } + +/** + * Test WString += implementation. + */ +static void testWStringConcat(void) +{ + String original = String("Im short"); + char classic[4]; + classic[0] = 'H'; + classic[1] = 'I'; + classic[2] = '!'; + classic[3] = '\0'; + + original.concat(String("- first amendment -")); + original.concat(classic); + original.concat('-'); + + TEST_ASSERT_EQUAL_STRING("Im short- first amendment -HI!-", original.c_str()); + + String tester = String(""); + tester.concat("Im new"); + TEST_ASSERT_EQUAL_STRING("Im new", tester.c_str()); +}