mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-18 12:54:25 +01:00
Starting to distinguish between empty strings and invalid (null) ones.
This commit is contained in:
parent
a5929892d4
commit
d3a5532d13
@ -114,7 +114,7 @@ inline void String::init(void)
|
|||||||
|
|
||||||
unsigned char String::reserve(unsigned int size)
|
unsigned char String::reserve(unsigned int size)
|
||||||
{
|
{
|
||||||
if (capacity >= size) return 1;
|
if (buffer && capacity >= size) return 1;
|
||||||
if (changeBuffer(size)) {
|
if (changeBuffer(size)) {
|
||||||
if (len == 0) buffer[0] = 0;
|
if (len == 0) buffer[0] = 0;
|
||||||
return 1;
|
return 1;
|
||||||
@ -139,11 +139,6 @@ unsigned char String::changeBuffer(unsigned int maxStrLen)
|
|||||||
|
|
||||||
String & String::copy(const char *cstr, unsigned int length)
|
String & String::copy(const char *cstr, unsigned int length)
|
||||||
{
|
{
|
||||||
if (length == 0) {
|
|
||||||
if (buffer) buffer[0] = 0;
|
|
||||||
len = 0;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
if (!reserve(length)) {
|
if (!reserve(length)) {
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
@ -204,6 +199,11 @@ String & String::operator = (const char *cstr)
|
|||||||
if (cstr) {
|
if (cstr) {
|
||||||
copy(cstr, strlen(cstr));
|
copy(cstr, strlen(cstr));
|
||||||
} else {
|
} else {
|
||||||
|
if (buffer) {
|
||||||
|
free(buffer);
|
||||||
|
capacity = 0;
|
||||||
|
buffer = NULL;
|
||||||
|
}
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -43,7 +43,7 @@ class String
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
String(const char *cstr = NULL);
|
String(const char *cstr = "");
|
||||||
String(const String &str);
|
String(const String &str);
|
||||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||||
String(String &&rval);
|
String(String &&rval);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user