mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-27 21:54:30 +01:00
Ported #1397 to SAM.
This commit is contained in:
parent
3d222cc372
commit
69e37647a6
@ -621,7 +621,7 @@ String String::substring(unsigned int left, unsigned int right) const
|
|||||||
left = temp;
|
left = temp;
|
||||||
}
|
}
|
||||||
String out;
|
String out;
|
||||||
if (left > len) return out;
|
if (left >= len) return out;
|
||||||
if (right > len) right = len;
|
if (right > len) right = len;
|
||||||
char temp = buffer[right]; // save the replaced character
|
char temp = buffer[right]; // save the replaced character
|
||||||
buffer[right] = '\0';
|
buffer[right] = '\0';
|
||||||
@ -686,15 +686,16 @@ void String::replace(const String& find, const String& replace)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void String::remove(unsigned int index){
|
void String::remove(unsigned int index){
|
||||||
if (index >= len) { return; }
|
// Pass the biggest integer as the count. The remove method
|
||||||
int count = len - index;
|
// below will take care of truncating it at the end of the
|
||||||
remove(index, count);
|
// string.
|
||||||
|
remove(index, (unsigned int)-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::remove(unsigned int index, unsigned int count){
|
void String::remove(unsigned int index, unsigned int count){
|
||||||
if (index >= len) { return; }
|
if (index >= len) { return; }
|
||||||
if (count <= 0) { return; }
|
if (count <= 0) { return; }
|
||||||
if (index + count > len) { count = len - index; }
|
if (count > len - index) { count = len - index; }
|
||||||
char *writeTo = buffer + index;
|
char *writeTo = buffer + index;
|
||||||
len = len - count;
|
len = len - count;
|
||||||
strncpy(writeTo, buffer + index + count,len - index);
|
strncpy(writeTo, buffer + index + count,len - index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user