Add replace and treplace to String (#2127)

* Add replace and treplace functions to String
This commit is contained in:
DragonFriend
2025-05-14 04:00:20 -05:00
committed by GitHub
parent abe4727c3a
commit 50b4d7aa35
4 changed files with 57 additions and 2 deletions

View File

@@ -195,6 +195,28 @@ fn void test_split_to_buffer()
free(strings);
}
fn void test_treplace()
{
String test = "Befriend some dragons?";
assert(test.treplace("some", "all") == "Befriend all dragons?");
assert(test.treplace("?", "!") == "Befriend some dragons!");
assert(test.treplace("Never", "Always") == "Befriend some dragons?");
}
fn void test_replace()
{
String test = "Befriend some dragons?";
String val = test.replace(mem, "some", "all");
test::eq(val, "Befriend all dragons?");
free(val);
val = test.replace(mem, "?", "!");
test::eq(val, "Befriend some dragons!");
free(val);
val = test.replace(mem, "Never", "Always");
test::eq(val, "Befriend some dragons?");
free(val);
}
fn void test_index_of()
{
String test = "hello world hello";
@@ -283,4 +305,4 @@ fn void tokenize_all_skip_last()
str.append("-");
}
test::eq(str.str_view(), "foo--bar-baz-");
}
}