aboutsummaryrefslogtreecommitdiff
path: root/cores
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2014-09-12 11:56:12 +0200
committerCristian Maglie <c.maglie@bug.st>2014-09-12 11:56:12 +0200
commit3155eeeae92ca78ec0ddda5db4a1da93b9002a86 (patch)
tree0456222aa0c3d19eb61cff9b0cd5ad4adc40ba25 /cores
parent0b094167de87edc14dedf775ed532a25f3d5d992 (diff)
parentfde95cf5b5ace06f497842f9329d5207c4834898 (diff)
Merge pull request #1937 from matthijskooijman/stringindex
String index fixes and cleanups
Diffstat (limited to 'cores')
-rw-r--r--cores/arduino/WString.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp
index ed880ce..dcd469d 100644
--- a/cores/arduino/WString.cpp
+++ b/cores/arduino/WString.cpp
@@ -619,7 +619,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';
@@ -684,15 +684,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);