aboutsummaryrefslogtreecommitdiff
path: root/cores
diff options
context:
space:
mode:
authorRyan Esteves <snargledorf@gmail.com>2013-06-05 14:08:59 -0400
committerRyan Esteves <snargledorf@gmail.com>2013-06-05 14:08:59 -0400
commit6bef2ada0627be776e463661ccbcdeba5a373f3a (patch)
treeef29cd25e4e7b742345c5ecbf57a4150ef5158de /cores
parentef4e8c65373f531ce6d37ff226a21fc9b358ff29 (diff)
Added remove methods to WString
Diffstat (limited to 'cores')
-rw-r--r--cores/arduino/WString.cpp16
-rw-r--r--cores/arduino/WString.h2
2 files changed, 18 insertions, 0 deletions
diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp
index c6839fc..aab2a54 100644
--- a/cores/arduino/WString.cpp
+++ b/cores/arduino/WString.cpp
@@ -604,6 +604,22 @@ 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);
+}
+
+void String::remove(unsigned int index, unsigned int count){
+ if (index >= len) { return; }
+ if (count <= 0) { return; }
+ if (index + count > len) { count = len - index; }
+ char *writeTo = buffer + index;
+ len = len - count;
+ strncpy(writeTo, buffer + index + count,len - index);
+ buffer[len] = 0;
+}
+
void String::toLowerCase(void)
{
if (!buffer) return;
diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h
index 642b016..b587a3d 100644
--- a/cores/arduino/WString.h
+++ b/cores/arduino/WString.h
@@ -164,6 +164,8 @@ public:
// modification
void replace(char find, char replace);
void replace(const String& find, const String& replace);
+ void remove(unsigned int index);
+ void remove(unsigned int index, unsigned int count);
void toLowerCase(void);
void toUpperCase(void);
void trim(void);