Skip to content

Commit c87b5ab

Browse files
committed
Commenting String API behavior.
1 parent c70b8a9 commit c87b5ab

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

hardware/arduino/cores/arduino/WString.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class String
4343
{
4444
public:
4545
// constructors
46+
// creates a copy of the initial value.
47+
// if the initial value is null or invalid, or if memory allocation
48+
// fails, the string will be marked as invalid (i.e. operator bool()
49+
// will return false).
4650
String(const char *cstr = "");
4751
String(const String &str);
4852
#ifdef __GXX_EXPERIMENTAL_CXX0X__
@@ -58,9 +62,15 @@ class String
5862
~String(void);
5963

6064
// memory management
65+
// return true on success, false on failure (in which case, the string
66+
// is left unchanged). reserve(0), if successful, will validate an
67+
// invalid string (i.e., operator bool() will return true afterwards)
6168
unsigned char reserve(unsigned int size);
6269
inline unsigned int length(void) const {return len;}
6370

71+
// creates a copy of the assigned value. if the value is null or
72+
// invalid, or if the memory allocation fails, the string will be
73+
// marked as invalid (operator bool() will return false).
6474
String & operator = (const String &rhs);
6575
String & operator = (const char *cstr);
6676
#ifdef __GXX_EXPERIMENTAL_CXX0X__
@@ -70,6 +80,9 @@ class String
7080
String & operator = (char c);
7181

7282
// concat
83+
// returns true on success, false on failure (in which case, the string
84+
// is left unchanged). if the argument is null or invalid, the
85+
// concatenation is considered unsucessful.
7386
unsigned char concat(const String &str);
7487
unsigned char concat(const char *cstr);
7588
unsigned char concat(char c);
@@ -78,6 +91,9 @@ class String
7891
unsigned char concat(unsigned int num);
7992
unsigned char concat(long num);
8093
unsigned char concat(unsigned long num);
94+
95+
// if there's not enough memory for the concatenated value, the string
96+
// will be left unchanged (but this isn't signalled in any way)
8197
String & operator += (const String &rhs) {concat(rhs); return (*this);}
8298
String & operator += (const char *cstr) {concat(cstr); return (*this);}
8399
String & operator += (char c) {concat(c); return (*this);}

0 commit comments

Comments
 (0)