mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
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.
This commit is contained in:
parent
6727c8a831
commit
f5f2e09636
@ -219,65 +219,61 @@ String & String::operator = (char c)
|
|||||||
/* concat */
|
/* concat */
|
||||||
/*********************************************/
|
/*********************************************/
|
||||||
|
|
||||||
String & String::concat(const String &s)
|
unsigned char String::concat(const String &s)
|
||||||
{
|
{
|
||||||
return concat(s.buffer, s.len);
|
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;
|
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);
|
strcpy(buffer + len, cstr);
|
||||||
len = newlen;
|
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));
|
if (!cstr) return 1; // nothing to append = success
|
||||||
return *this;
|
return concat(cstr, strlen(cstr));
|
||||||
}
|
}
|
||||||
|
|
||||||
String & String::concat(char c)
|
unsigned char String::concat(char c)
|
||||||
{
|
{
|
||||||
char buf[2];
|
char buf[2];
|
||||||
buf[0] = c;
|
buf[0] = c;
|
||||||
buf[1] = 0;
|
buf[1] = 0;
|
||||||
concat(buf, 1);
|
return concat(buf, 1);
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String & String::concat(int num)
|
unsigned char String::concat(int num)
|
||||||
{
|
{
|
||||||
char buf[7];
|
char buf[7];
|
||||||
itoa(num, buf, 10);
|
itoa(num, buf, 10);
|
||||||
concat(buf, strlen(buf));
|
return concat(buf, strlen(buf));
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String & String::concat(unsigned int num)
|
unsigned char String::concat(unsigned int num)
|
||||||
{
|
{
|
||||||
char buf[6];
|
char buf[6];
|
||||||
utoa(num, buf, 10);
|
utoa(num, buf, 10);
|
||||||
concat(buf, strlen(buf));
|
return concat(buf, strlen(buf));
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String & String::concat(long num)
|
unsigned char String::concat(long num)
|
||||||
{
|
{
|
||||||
char buf[12];
|
char buf[12];
|
||||||
ltoa(num, buf, 10);
|
ltoa(num, buf, 10);
|
||||||
concat(buf, strlen(buf));
|
return concat(buf, strlen(buf));
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String & String::concat(unsigned long num)
|
unsigned char String::concat(unsigned long num)
|
||||||
{
|
{
|
||||||
char buf[11];
|
char buf[11];
|
||||||
ultoa(num, buf, 10);
|
ultoa(num, buf, 10);
|
||||||
concat(buf, strlen(buf));
|
return concat(buf, strlen(buf));
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************/
|
/*********************************************/
|
||||||
|
@ -73,22 +73,22 @@ public:
|
|||||||
String & operator = (char c);
|
String & operator = (char c);
|
||||||
|
|
||||||
// concat
|
// concat
|
||||||
String & concat(const String &str);
|
unsigned char concat(const String &str);
|
||||||
String & concat(const char *cstr);
|
unsigned char concat(const char *cstr);
|
||||||
String & concat(char c);
|
unsigned char concat(char c);
|
||||||
String & concat(unsigned char c) {return concat((char)c);}
|
unsigned char concat(unsigned char c) {return concat((char)c);}
|
||||||
String & concat(int num);
|
unsigned char concat(int num);
|
||||||
String & concat(unsigned int num);
|
unsigned char concat(unsigned int num);
|
||||||
String & concat(long num);
|
unsigned char concat(long num);
|
||||||
String & concat(unsigned long num);
|
unsigned char concat(unsigned long num);
|
||||||
String & operator += (const String &rhs) {return concat(rhs);}
|
String & operator += (const String &rhs) {concat(rhs); return (*this);}
|
||||||
String & operator += (const char *cstr) {return concat(cstr);}
|
String & operator += (const char *cstr) {concat(cstr); return (*this);}
|
||||||
String & operator += (char c) {return concat(c);}
|
String & operator += (char c) {concat(c); return (*this);}
|
||||||
String & operator += (unsigned char c) {return concat((char)c);}
|
String & operator += (unsigned char c) {concat((char)c); return (*this);}
|
||||||
String & operator += (int num) {return concat(num);}
|
String & operator += (int num) {concat(num); return (*this);}
|
||||||
String & operator += (unsigned int num) {return concat(num);}
|
String & operator += (unsigned int num) {concat(num); return (*this);}
|
||||||
String & operator += (long num) {return concat(num);}
|
String & operator += (long num) {concat(num); return (*this);}
|
||||||
String & operator += (unsigned long num) {return concat(num);}
|
String & operator += (unsigned long num) {concat(num); return (*this);}
|
||||||
|
|
||||||
// concatenate
|
// concatenate
|
||||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
|
friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
|
||||||
@ -156,7 +156,7 @@ protected:
|
|||||||
protected:
|
protected:
|
||||||
void init(void);
|
void init(void);
|
||||||
unsigned char changeBuffer(unsigned int maxStrLen);
|
unsigned char changeBuffer(unsigned int maxStrLen);
|
||||||
String & concat(const char *cstr, unsigned int length);
|
unsigned char concat(const char *cstr, unsigned int length);
|
||||||
};
|
};
|
||||||
|
|
||||||
class StringSumHelper : public String
|
class StringSumHelper : public String
|
||||||
|
Loading…
x
Reference in New Issue
Block a user