File tree 2 files changed +16
-0
lines changed
hardware/arduino/avr/cores/arduino
2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,13 @@ unsigned char String::reserve(unsigned int size)
152
152
return 0 ;
153
153
}
154
154
155
+ unsigned int String::validate ( bool remainder )
156
+ {
157
+ if ( !remainder ) len = 0 ;
158
+ while ( len < capacity && buffer[ len ] ) ++len;
159
+ return len;
160
+ }
161
+
155
162
unsigned char String::changeBuffer (unsigned int maxStrLen)
156
163
{
157
164
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