Skip to content

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

Closed
@kiiv-cz

Description

@kiiv-cz
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 arduino/ArduinoCore-megaavr#109

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy