defragster
Senior Member+
Used www_GitHub to edit a fork and did a pull request:: .../PaulStoffregen/cores/pull/165
This code doesn't actually test the overlapping substring case. "twostring.substring()" creates a temporary string with a new buffer.Code:else if ( twostring.length() < 10000 ) { Serial.print( twostring ); Serial.println( "<<< SS0"); twostring += twostring.substring( 0, 5 ); Serial.print( twostring ); Serial.println( "<<< SS1"); twostring += twostring.substring( 5, 9 ); Serial.print( twostring ); Serial.println( "<<< SS2"); twostring += twostring.substring( 10, twostring.length() ); Serial.print( twostring ); Serial.println( "<<< SS3"); }
twostring.append(twostring.c_str(), 5);
twostring.append(twostring.c_str() + 5, 4);
twostring += twostring.c_str() + 10;
String & String::append(const char *cstr)
{
if (cstr) append(cstr, strlen(cstr));
return *this;
}
... twostring.append(twostring.c_str() + 5);
This should compile. As should:That was in the tni p_28 and it what gave me the error on compile.... twostring.append(twostring.c_str() + 5);
twostring += twostring.c_str() + 10;
You can get at the internal buffer via 2 public methods, c_str() and operator[] (e.g. char* ptr = &twostring[2]).Given that the szCstr is the underlying storage - it can't be publicly exposed easily.
class StringTest: public String {
public:
using String::append;
};
void test() {
StringTest twostring;
twostring.append(twostring.c_str(), 5);
twostring.append(twostring.c_str() + 5, 4);
twostring += twostring.c_str() + 10;
}