return r;
}
+void pakfire_strings_pop(char*** array) {
+ char* s = NULL;
+
+ if (!array)
+ return;
+
+ // Fetch the length
+ size_t length = pakfire_strings_length(*array);
+
+ // Return if the array is empty
+ if (!length)
+ return;
+
+ // Free the string
+ s = (*array)[length - 1];
+ if (s)
+ free(s);
+
+ // Reset the pointer
+ (*array)[length - 1] = NULL;
+}
+
/*
This function dumps the string array to the console. This is useful for debugging only.
*/
int pakfire_strings_appendf(char*** array, const char* format, ...)
__attribute__((format(printf, 2, 3)));
int pakfire_strings_appendm(char*** array, const char** strings);
+void pakfire_strings_pop(char*** array);
int pakfire_strings_dump(char** array);
return r;
}
+static int test_strings_pop(const struct test* t) {
+ char** array = NULL;
+ int r = EXIT_FAILURE;
+
+ // Append a few strings
+ ASSERT_SUCCESS(pakfire_strings_append(&array, "a"));
+ ASSERT_SUCCESS(pakfire_strings_append(&array, "b"));
+ ASSERT_SUCCESS(pakfire_strings_append(&array, "c"));
+
+ // The length should now be three
+ ASSERT_EQUALS(pakfire_strings_length(array), 3);
+
+ // Let's pop something
+ pakfire_strings_pop(&array);
+
+ // Now this should be shorter
+ ASSERT_EQUALS(pakfire_strings_length(array), 2);
+
+ // Let's pop something more
+ pakfire_strings_pop(&array);
+
+ // Now this should be even shorter
+ ASSERT_EQUALS(pakfire_strings_length(array), 1);
+
+ // Let's pop once more
+ pakfire_strings_pop(&array);
+
+ // Now this should be empty
+ ASSERT_EQUALS(pakfire_strings_length(array), 0);
+
+ // Pop the empty array
+ pakfire_strings_pop(&array);
+
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ return r;
+}
+
int main(int argc, const char* argv[]) {
testsuite_add_test(test_string_set, 0);
testsuite_add_test(test_string_setn, 0);
testsuite_add_test(test_string_contains_whitespace, 0);
testsuite_add_test(test_string_search, 0);
testsuite_add_test(test_truncate, 0);
+ testsuite_add_test(test_strings_pop, 0);
return testsuite_run(argc, argv);
}