From 98b403114c3d9edcb6b74938f07c68dccc3c2489 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 12 Mar 2011 14:03:34 -0500 Subject: Modifying String.concat() to return success or failure, not this. Which means you can't chain multiple concat() calls together, but you can check if they succeeded or not. --- cores/arduino/WString.cpp | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'cores/arduino/WString.cpp') diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index e9f71d1..5dcf585 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -219,65 +219,61 @@ String & String::operator = (char c) /* concat */ /*********************************************/ -String & String::concat(const String &s) +unsigned char String::concat(const String &s) { return concat(s.buffer, s.len); } -String & String::concat(const char *cstr, unsigned int length) +unsigned char String::concat(const char *cstr, unsigned int length) { unsigned int newlen = len + length; - if (length == 0 || !reserve(newlen)) return *this; + if (!cstr || length == 0) return 1; // nothing to append = success + if (!reserve(newlen)) return 0; strcpy(buffer + len, cstr); len = newlen; - return *this; + return 1; } -String & String::concat(const char *cstr) +unsigned char String::concat(const char *cstr) { - if (cstr) concat(cstr, strlen(cstr)); - return *this; + if (!cstr) return 1; // nothing to append = success + return concat(cstr, strlen(cstr)); } -String & String::concat(char c) +unsigned char String::concat(char c) { char buf[2]; buf[0] = c; buf[1] = 0; - concat(buf, 1); - return *this; + return concat(buf, 1); } -String & String::concat(int num) +unsigned char String::concat(int num) { char buf[7]; itoa(num, buf, 10); - concat(buf, strlen(buf)); - return *this; + return concat(buf, strlen(buf)); } -String & String::concat(unsigned int num) +unsigned char String::concat(unsigned int num) { char buf[6]; utoa(num, buf, 10); - concat(buf, strlen(buf)); - return *this; + return concat(buf, strlen(buf)); } -String & String::concat(long num) +unsigned char String::concat(long num) { char buf[12]; ltoa(num, buf, 10); - concat(buf, strlen(buf)); - return *this; + return concat(buf, strlen(buf)); } -String & String::concat(unsigned long num) +unsigned char String::concat(unsigned long num) { char buf[11]; ultoa(num, buf, 10); - concat(buf, strlen(buf)); - return *this; + return concat(buf, strlen(buf)); } /*********************************************/ -- cgit v1.2.3-18-g5258