diff --git a/src/utils.c b/src/utils.c index adfa14b..34f7265 100644 --- a/src/utils.c +++ b/src/utils.c @@ -44,16 +44,6 @@ char *string_replace_at(char *buf, int pos, int len, const char *repl) return tmp; } -char *string_replace(const char *needle, const char *replacement, char *haystack) -{ - char *start; - start = strstr(haystack, needle); - if (!start) - return haystack; - - return string_replace_at(haystack, (start - haystack), strlen(needle), replacement); -} - char *string_replace_all(const char *needle, const char *replacement, char *haystack) { char *start; @@ -134,7 +124,7 @@ char *string_to_path(char *string) if (string && STRN_EQ(string, "~/", 2)) { char *home = g_strconcat(getenv("HOME"), "/", NULL); - string = string_replace("~/", home, string); + string = string_replace_at(string, 0, 2, home); g_free(home); } diff --git a/src/utils.h b/src/utils.h index 6ea3b4e..1e9cd4d 100644 --- a/src/utils.h +++ b/src/utils.h @@ -25,9 +25,6 @@ char *string_replace_all(const char *needle, const char *replacement, char *hays /* replace characters with at position of the string */ char *string_replace_at(char *buf, int pos, int len, const char *repl); -/* replace needle with replacement in haystack */ -char *string_replace(const char *needle, const char *replacement, char *haystack); - char *string_append(char *a, const char *b, const char *sep); /* strip content between two delimiter characters (inplace) */ diff --git a/test/utils.c b/test/utils.c index b99af9e..f59e00f 100644 --- a/test/utils.c +++ b/test/utils.c @@ -48,28 +48,6 @@ TEST test_string_replace_all(void) PASS(); } -TEST test_string_replace(void) -{ - char *text = malloc(128 * sizeof(char)); - strcpy(text, "aaaaa"); - ASSERT_STR_EQ("baaaa", (text = string_replace("a", "b", text)) ); - - strcpy(text, ""); - ASSERT_STR_EQ((text = string_replace("a", "b", text)), ""); - - strcpy(text, "Nothing to replace"); - ASSERT_STR_EQ((text = string_replace("z", "a", text)), "Nothing to replace"); - - strcpy(text, "Reverse this"); - ASSERT_STR_EQ("Reverse sith", (text = string_replace("this", "sith", text))); - - strcpy(text, "abcdabc"); - ASSERT_STR_EQ("xyzabcdabc", (text = string_replace("a", "xyza", text))); - - free(text); - PASS(); -} - TEST test_string_append(void) { char *exp; @@ -202,7 +180,6 @@ SUITE(suite_utils) { RUN_TEST(test_string_replace_char); RUN_TEST(test_string_replace_all); - RUN_TEST(test_string_replace); RUN_TEST(test_string_append); RUN_TEST(test_string_strip_quotes); RUN_TEST(test_string_strip_delimited);