ArduinoCore-API icon indicating copy to clipboard operation
ArduinoCore-API copied to clipboard

String::replace doesn't work when replacing multiple occurencies of longer String by shorter one

Open kiiv-cz opened this issue 3 years ago • 0 comments

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");
}

The last testcase fails as it doesn't replace anything at all. Other two works as expected.

Reported in https://github.com/arduino/ArduinoCore-megaavr/issues/109

kiiv-cz avatar Aug 29 '23 21:08 kiiv-cz