[gnoduino] Added remove methods to WString
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnoduino] Added remove methods to WString
- Date: Thu, 17 Oct 2013 23:37:17 +0000 (UTC)
commit 5305235fdf57ef00aa4915645b8a05a11c081c0c
Author: Ryan Esteves <snargledorf gmail com>
Date: Wed Jun 5 14:08:59 2013 -0400
Added remove methods to WString
hardware/arduino/cores/arduino/WString.cpp | 16 ++++++++++++++++
hardware/arduino/cores/arduino/WString.h | 2 ++
2 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/hardware/arduino/cores/arduino/WString.cpp b/hardware/arduino/cores/arduino/WString.cpp
index c6839fc..aab2a54 100644
--- a/hardware/arduino/cores/arduino/WString.cpp
+++ b/hardware/arduino/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/hardware/arduino/cores/arduino/WString.h b/hardware/arduino/cores/arduino/WString.h
index 642b016..b587a3d 100644
--- a/hardware/arduino/cores/arduino/WString.h
+++ b/hardware/arduino/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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]