| 334 | /*********************************************/ |
| 335 | |
| 336 | bool String::concat(const char* cstr, size_t length) |
| 337 | { |
| 338 | if(length == 0) { |
| 339 | return true; // Nothing to add |
| 340 | } |
| 341 | if(!cstr) { |
| 342 | return false; // Bad argument (length is non-zero) |
| 343 | } |
| 344 | |
| 345 | auto len = this->length(); |
| 346 | size_t newlen = len + length; |
| 347 | |
| 348 | // Appending all or part of self requires special handling |
| 349 | auto buf = buffer(); |
| 350 | if(cstr >= buf && cstr < (buf + len)) { |
| 351 | auto offset = cstr - buf; |
| 352 | if(!reserve(newlen)) { |
| 353 | return false; |
| 354 | } |
| 355 | buf = buffer(); |
| 356 | memcpy(buf + len, buf + offset, length); |
| 357 | setlen(newlen); |
| 358 | return true; |
| 359 | } |
| 360 | |
| 361 | if(!reserve(newlen)) { |
| 362 | return false; |
| 363 | } |
| 364 | memcpy(buffer() + len, cstr, length); |
| 365 | setlen(newlen); |
| 366 | return true; |
| 367 | } |
| 368 | |
| 369 | bool String::concat(const FlashString& fstr) |
| 370 | { |
no test coverage detected