Skip to content

Commit

Permalink
Added remove methods to WString
Browse files Browse the repository at this point in the history
  • Loading branch information
snargledorf committed Jun 5, 2013
1 parent 22320db commit 0778f8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions hardware/arduino/cores/arduino/WString.cpp
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions hardware/arduino/cores/arduino/WString.h
Expand Up @@ -164,6 +164,8 @@ class String
// 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);
Expand Down

0 comments on commit 0778f8a

Please sign in to comment.