Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 6 additions & 6 deletions api/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ void String::move(String &rhs)
String & String::operator = (const String &rhs)
{
if (this == &rhs) return *this;

if (rhs.buffer) copy(rhs.buffer, rhs.len);
else invalidate();

return *this;
}

Expand All @@ -253,7 +253,7 @@ String & String::operator = (const char *cstr)
{
if (cstr) copy(cstr, strlen(cstr));
else invalidate();

return *this;
}

Expand Down Expand Up @@ -484,7 +484,7 @@ bool String::equalsIgnoreCase( const String &s2 ) const
const char *p2 = s2.buffer;
while (*p1) {
if (tolower(*p1++) != tolower(*p2++)) return false;
}
}
return true;
}

Expand Down Expand Up @@ -515,7 +515,7 @@ char String::charAt(unsigned int loc) const
return operator[](loc);
}

void String::setCharAt(unsigned int loc, char c)
void String::setCharAt(unsigned int loc, char c)
{
if (loc < len) buffer[loc] = c;
}
Expand Down Expand Up @@ -652,9 +652,9 @@ void String::replace(const String& find, const String& replace)
}
} else if (diff < 0) {
unsigned int size = len; // compute size needed for result
diff = 0 - diff;
while ((foundAt = strstr(readFrom, find.buffer)) != NULL) {
readFrom = foundAt + find.len;
diff = 0 - diff;
size -= diff;
}
if (size == len) return;
Expand Down
21 changes: 21 additions & 0 deletions test/src/String/test_replace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,24 @@ TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than '
str.replace(arduino::String("ll"), arduino::String("111"));
REQUIRE(str == "He111o Arduino!");
}

TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than 'replace' multiple occurencies", "[String-replace-08]")
{
arduino::String str("Hello Arduino! Hello, Hello, Hello");
str.replace(arduino::String("ll"), arduino::String("lll"));
REQUIRE(str == "Helllo Arduino! Helllo, Helllo, Helllo");
}

TEST_CASE ("Testing String::replace(String, String) substr 'find' same length as 'replace' multiple occurencies", "[String-replace-09]")
{
arduino::String str("Hello Arduino! Hello, Hello, Hello");
str.replace(arduino::String("ll"), arduino::String("11"));
REQUIRE(str == "He11o Arduino! He11o, He11o, He11o");
}

TEST_CASE ("Testing String::replace(String, String) substr 'find' larger than 'replace' multiple occurencies", "[String-replace-10]")
{
arduino::String str("Helllo Arduino! Helllo, Helllo, Helllo");
str.replace(arduino::String("lll"), arduino::String("ll"));
REQUIRE(str == "Hello Arduino! Hello, Hello, Hello");
}