1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-16 00:43:00 +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:
Earle F. Philhower, III
2019-11-14 00:58:07 +01:00
committed by david gauchard
parent d2d0ee3d43
commit 09896d5287
3 changed files with 18 additions and 1 deletions

View File

@ -331,6 +331,7 @@ unsigned char String::concat(const char *cstr, unsigned int length) {
return 0;
memmove_P(wbuffer() + len(), cstr, length + 1);
setLen(newlen);
wbuffer()[newlen] = 0;
return 1;
}

View File

@ -116,6 +116,7 @@ class String {
unsigned char concat(float num);
unsigned char concat(double num);
unsigned char concat(const __FlashStringHelper * str);
unsigned char concat(const char *cstr, unsigned int length);
// if there's not enough memory for the concatenated value, the string
// will be left unchanged (but this isn't signalled in any way)
@ -311,7 +312,6 @@ class String {
void init(void);
void invalidate(void);
unsigned char changeBuffer(unsigned int maxStrLen);
unsigned char concat(const char *cstr, unsigned int length);
// copy and move
String & copy(const char *cstr, unsigned int length);