mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
Add String::concat(char*, len) to allow non null-term strings (#6754)
* Add comcat(char*, len) to Sting Fixes #5061 Adds a concat(const char *data, int len) method which allows arbitrary sequences of data (including ones w/embedded \0s) to be appended to a String. May be useful for certain MQTT operations. Adds sanity test for the feature to host suite * Review comment cleanups
This commit is contained in:
committed by
david gauchard
parent
d2d0ee3d43
commit
09896d5287
@ -131,6 +131,22 @@ TEST_CASE("String concantenation", "[core][String]")
|
||||
REQUIRE(str == "-100");
|
||||
str = String((long)-100, 10);
|
||||
REQUIRE(str == "-100");
|
||||
// Non-zero-terminated array concatenation
|
||||
const char buff[] = "abcdefg";
|
||||
String n;
|
||||
n = "1234567890"; // Make it a SSO string, fill with non-0 data
|
||||
n = "1"; // Overwrite [1] with 0, but leave old junk in SSO space still
|
||||
n.concat(buff, 3);
|
||||
REQUIRE(n == "1abc"); // Ensure the trailing 0 is always present even w/this funky concat
|
||||
for (int i=0; i<20; i++)
|
||||
n.concat(buff, 1); // Add 20 'a's to go from SSO to normal string
|
||||
REQUIRE(n == "1abcaaaaaaaaaaaaaaaaaaaa");
|
||||
n = "";
|
||||
for (int i=0; i<=5; i++)
|
||||
n.concat(buff, i);
|
||||
REQUIRE(n == "aababcabcdabcde");
|
||||
n.concat(buff, 0); // And check no add'n
|
||||
REQUIRE(n == "aababcabcdabcde");
|
||||
}
|
||||
|
||||
TEST_CASE("String comparison", "[core][String]")
|
||||
|
Reference in New Issue
Block a user