string-util: readd string_erase()

This was dropped in 8e27167cc9, but is
actually useful for some usecases still.
This commit is contained in:
Lennart Poettering
2019-12-04 10:58:12 +01:00
parent 282bde1066
commit 53caaffdf4
3 changed files with 36 additions and 0 deletions
+24
View File
@@ -9,6 +9,29 @@
#include "utf8.h"
#include "util.h"
static void test_string_erase(void) {
char *x;
x = strdupa("");
assert_se(streq(string_erase(x), ""));
x = strdupa("1");
assert_se(streq(string_erase(x), ""));
x = strdupa("123456789");
assert_se(streq(string_erase(x), ""));
assert_se(x[1] == '\0');
assert_se(x[2] == '\0');
assert_se(x[3] == '\0');
assert_se(x[4] == '\0');
assert_se(x[5] == '\0');
assert_se(x[6] == '\0');
assert_se(x[7] == '\0');
assert_se(x[8] == '\0');
assert_se(x[9] == '\0');
}
static void test_free_and_strndup_one(char **t, const char *src, size_t l, const char *expected, bool change) {
int r;
@@ -543,6 +566,7 @@ static void test_memory_startswith_no_case(void) {
int main(int argc, char *argv[]) {
test_setup_logging(LOG_DEBUG);
test_string_erase();
test_free_and_strndup();
test_ascii_strcasecmp_n();
test_ascii_strcasecmp_nn();