mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Merge pull request #92475 from AThousandShips/string_replace_char
Add `String::replace_char(s)` methods for performance and convenience
This commit is contained in:
commit
cade15a163
67 changed files with 297 additions and 137 deletions
|
|
@ -112,7 +112,7 @@ TEST_CASE("[ProjectSettings] localize_path") {
|
|||
TestProjectSettingsInternalsAccessor::resource_path() = DirAccess::create(DirAccess::ACCESS_FILESYSTEM)->get_current_dir();
|
||||
String root_path = ProjectSettings::get_singleton()->get_resource_path();
|
||||
#ifdef WINDOWS_ENABLED
|
||||
String root_path_win = ProjectSettings::get_singleton()->get_resource_path().replace("/", "\\");
|
||||
String root_path_win = ProjectSettings::get_singleton()->get_resource_path().replace_char('/', '\\');
|
||||
#endif
|
||||
|
||||
CHECK_EQ(ProjectSettings::get_singleton()->localize_path("filename"), "res://filename");
|
||||
|
|
|
|||
|
|
@ -476,6 +476,27 @@ TEST_CASE("[String] Find and replace") {
|
|||
MULTICHECK_STRING_STRING_EQ(s, replacen, "Y", "Y", "HappY BirthdaY, Anna!");
|
||||
}
|
||||
|
||||
TEST_CASE("[String] replace_char") {
|
||||
String s = "Banana";
|
||||
CHECK(s.replace_char('n', 'x') == "Baxaxa");
|
||||
CHECK(s.replace_char('\0', 'x') == "Banana");
|
||||
ERR_PRINT_OFF
|
||||
CHECK(s.replace_char('n', '\0') == "Banana");
|
||||
ERR_PRINT_ON
|
||||
}
|
||||
|
||||
TEST_CASE("[String] replace_chars") {
|
||||
String s = "Banana";
|
||||
CHECK(s.replace_chars(String("Bn"), 'x') == "xaxaxa");
|
||||
CHECK(s.replace_chars("Bn", 'x') == "xaxaxa");
|
||||
CHECK(s.replace_chars(String(), 'x') == "Banana");
|
||||
CHECK(s.replace_chars("", 'x') == "Banana");
|
||||
ERR_PRINT_OFF
|
||||
CHECK(s.replace_chars(String("Bn"), '\0') == "Banana");
|
||||
CHECK(s.replace_chars("Bn", '\0') == "Banana");
|
||||
ERR_PRINT_ON
|
||||
}
|
||||
|
||||
TEST_CASE("[String] Insertion") {
|
||||
String s = "Who is Frederic?";
|
||||
s = s.insert(s.find("?"), " Chopin");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue