]> git.ipfire.org Git - pakfire.git/commitdiff
strings: Remove split function
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 2 Oct 2023 16:11:39 +0000 (16:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 2 Oct 2023 16:11:39 +0000 (16:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/string.h
src/libpakfire/string.c
tests/libpakfire/string.c

index 54091248944a66bcc51b9b0c8a1acdc701f5bf42..3cb8532c4ec9aa013b37ce2aeed5162ed1715538 100644 (file)
@@ -53,10 +53,8 @@ void pakfire_string_strip(char* s);
 
 int pakfire_string_partition(const char* s, const char* delim, char** s1, char** s2);
 char* pakfire_string_replace(const char* s, const char* pattern, const char* repl);
-char** pakfire_string_split(const char* s, char delim);
 char* pakfire_string_join(char** list, const char* delim);
 
-
 /*
        Cleanup Stuff
 */
index 330abc917d183965aa51bf1ef8703a6d94e52e45..88aac3281e54e4672d8c11cb9f25d5bcdc507441 100644 (file)
@@ -243,49 +243,6 @@ static unsigned int pakfire_chrcnt(const char* s, char delim) {
        return count;
 }
 
-char** pakfire_string_split(const char* s, char delim) {
-       char** array = NULL;
-
-       if (!s) {
-               errno = EINVAL;
-               return NULL;
-       }
-
-       // Count how often we need to split
-       unsigned int count = pakfire_chrcnt(s, delim) + 1;
-
-       // Allocate array
-       array = calloc(count + 1, sizeof(*array));
-       if (!array)
-               return NULL;
-
-       // Copy string to stack
-       char* p = strdupa(s);
-       if (!p)
-               return NULL;
-
-       unsigned int i = 0;
-       while (*p) {
-               char* e = strchr(p, delim);
-
-               // Terminate the string
-               if (e)
-                       *e = '\0';
-
-               // Add string to the array
-               array[i++] = strdup(p);
-
-               // End loop when we reached the end
-               if (!e)
-                       break;
-
-               // Or continue at the next line
-               p = e + 1;
-       }
-
-       return array;
-}
-
 char* pakfire_string_join(char** list, const char* delim) {
        // Validate input
        if (!list || !delim) {
index c8520be3102c62a7bcc4c009e12b62e0bc68454b..38e56479d6b74483f1ae3ad109651598c8e8110a 100644 (file)
@@ -159,44 +159,6 @@ FAIL:
        return EXIT_FAILURE;
 }
 
-static int test_string_split(const struct test* t) {
-       char** result = pakfire_string_split(NULL, 'X');
-
-       // Must return on invalid input
-       ASSERT_ERRNO(!result, EINVAL);
-
-       // Split a string
-       result = pakfire_string_split("ABCXABCXABC", 'X');
-       ASSERT(result);
-
-       ASSERT_STRING_EQUALS(result[0], "ABC");
-       ASSERT_STRING_EQUALS(result[1], "ABC");
-       ASSERT_STRING_EQUALS(result[2], "ABC");
-       ASSERT_NULL(result[3]);
-
-       // Split a string withtout the delimiter
-       result = pakfire_string_split("ABCABC", 'X');
-       ASSERT(result);
-
-       ASSERT_STRING_EQUALS(result[0], "ABCABC");
-       ASSERT_NULL(result[1]);
-
-       // String with only delimiters
-       result = pakfire_string_split("XXXX", 'X');
-       ASSERT(result);
-
-       ASSERT_STRING_EQUALS(result[0], "");
-       ASSERT_STRING_EQUALS(result[1], "");
-       ASSERT_STRING_EQUALS(result[2], "");
-       ASSERT_STRING_EQUALS(result[3], "");
-       ASSERT_NULL(result[4]);
-
-       return EXIT_SUCCESS;
-
-FAIL:
-       return EXIT_FAILURE;
-}
-
 static int test_string_join(const struct test* t) {
        char* s = NULL;
 
@@ -369,7 +331,6 @@ int main(int argc, const char* argv[]) {
        testsuite_add_test(test_string_matches);
        testsuite_add_test(test_string_partition);
        testsuite_add_test(test_string_replace);
-       testsuite_add_test(test_string_split);
        testsuite_add_test(test_string_join);
        testsuite_add_test(test_format_size);
        testsuite_add_test(test_parse_bytes);