File tree 2 files changed +16
-0
lines changed
hardware/arduino/sam/cores/arduino
2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,13 @@ unsigned char String::reserve(unsigned int size)
154
154
return 0 ;
155
155
}
156
156
157
+ unsigned int String::validate ( bool remainder )
158
+ {
159
+ if ( !remainder ) len = 0 ;
160
+ while ( len < capacity && buffer[ len ] ) ++len;
161
+ return len;
162
+ }
163
+
157
164
unsigned char String::changeBuffer (unsigned int maxStrLen)
158
165
{
159
166
char *newbuffer = (char *)realloc (buffer, maxStrLen + 1 );
Original file line number Diff line number Diff line change @@ -78,6 +78,15 @@ class String
78
78
// is left unchanged). reserve(0), if successful, will validate an
79
79
// invalid string (i.e., "if (s)" will be true afterwards)
80
80
unsigned char reserve (unsigned int size);
81
+
82
+ // If reserved data is modified externally using c_str()/&str[x]
83
+ // this function will allow the contents to be validated and ready
84
+ // for use with the String functionality.
85
+
86
+ // If remainder is true, only the reserved buffer is validated (capacity - len bytes)
87
+ // If remainder is false, the entire buffer is re-validated.
88
+ unsigned int validate ( bool remainder = false );
89
+
81
90
inline unsigned int length (void ) const {return len;}
82
91
83
92
// creates a copy of the assigned value. if the value is null or
You can’t perform that action at this time.
0 commit comments