1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Ported #1397 to SAM.

This commit is contained in:
Cristian Maglie 2014-09-12 12:06:00 +02:00
parent 3d222cc372
commit 69e37647a6

View File

@ -621,7 +621,7 @@ String String::substring(unsigned int left, unsigned int right) const
left = temp;
}
String out;
if (left > len) return out;
if (left >= len) return out;
if (right > len) right = len;
char temp = buffer[right]; // save the replaced character
buffer[right] = '\0';
@ -686,15 +686,16 @@ void String::replace(const String& find, const String& replace)
}
void String::remove(unsigned int index){
if (index >= len) { return; }
int count = len - index;
remove(index, count);
// Pass the biggest integer as the count. The remove method
// below will take care of truncating it at the end of the
// string.
remove(index, (unsigned int)-1);
}
void String::remove(unsigned int index, unsigned int count){
if (index >= len) { return; }
if (count <= 0) { return; }
if (index + count > len) { count = len - index; }
if (count > len - index) { count = len - index; }
char *writeTo = buffer + index;
len = len - count;
strncpy(writeTo, buffer + index + count,len - index);