Skip to content

Added remove methods to the WString class for improved parsing. #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions hardware/arduino/cores/arduino/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,27 @@ 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 temp[len - count];
for (int i = 0; i < index; i++)
temp[i] = buffer[i];
for(int i = (count + index); i < len; i++)
temp[i - (count)] = buffer[i];
char *p = temp;
len = len - count;
memcpy(buffer, p, len);
buffer[len] = '\0';
}

void String::toLowerCase(void)
{
if (!buffer) return;
Expand Down
2 changes: 2 additions & 0 deletions hardware/arduino/cores/arduino/WString.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,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