mirror of
https://github.com/systemd/systemd.git
synced 2025-03-25 18:50:18 +03:00
string-util: introduce strrepa
This commit is contained in:
parent
62efc7629b
commit
00614746e9
@ -196,6 +196,17 @@ int strextendf_with_separator(char **x, const char *separator, const char *forma
|
||||
|
||||
char *strrep(const char *s, unsigned n);
|
||||
|
||||
#define strrepa(s, n) \
|
||||
({ \
|
||||
char *_d_, *_p_; \
|
||||
size_t _len_ = strlen(s) * n; \
|
||||
_p_ = _d_ = newa(char, _len_ + 1); \
|
||||
for (unsigned _i_ = 0; _i_ < n; _i_++) \
|
||||
_p_ = stpcpy(_p_, s); \
|
||||
*_p_ = 0; \
|
||||
_d_; \
|
||||
})
|
||||
|
||||
int split_pair(const char *s, const char *sep, char **l, char **r);
|
||||
|
||||
int free_and_strdup(char **p, const char *s);
|
||||
|
@ -260,6 +260,8 @@ TEST(strextend_with_separator) {
|
||||
|
||||
TEST(strrep) {
|
||||
_cleanup_free_ char *one = NULL, *three = NULL, *zero = NULL;
|
||||
char *onea, *threea;
|
||||
|
||||
one = strrep("waldo", 1);
|
||||
three = strrep("waldo", 3);
|
||||
zero = strrep("waldo", 0);
|
||||
@ -267,6 +269,12 @@ TEST(strrep) {
|
||||
assert_se(streq(one, "waldo"));
|
||||
assert_se(streq(three, "waldowaldowaldo"));
|
||||
assert_se(streq(zero, ""));
|
||||
|
||||
onea = strrepa("waldo", 1);
|
||||
threea = strrepa("waldo", 3);
|
||||
|
||||
assert_se(streq(onea, "waldo"));
|
||||
assert_se(streq(threea, "waldowaldowaldo"));
|
||||
}
|
||||
|
||||
TEST(string_has_cc) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user