strbuf.c: Added strbuf_append_repeat function
This commit is contained in:
parent
0416fea36a
commit
f06a528ad0
3 changed files with 12 additions and 2 deletions
|
|
@ -102,6 +102,14 @@ void strbuf_append_ch(strbuf_t *s, char ch) {
|
|||
s->buf[s->len] = '\0';
|
||||
}
|
||||
|
||||
void strbuf_append_repeat(strbuf_t *s, char ch, size_t len) {
|
||||
|
||||
strbuf_expand(s, len);
|
||||
memset(s->buf + s->len, ch, len);
|
||||
s->len += len;
|
||||
s->buf[s->len] = '\0';
|
||||
}
|
||||
|
||||
void strbuf_rchop(strbuf_t *s, char ch) {
|
||||
|
||||
int i;
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ void strbuf_append_str(strbuf_t *s, const char *str);
|
|||
|
||||
void strbuf_append_ch(strbuf_t *s, char ch);
|
||||
|
||||
void strbuf_append_repeat(strbuf_t *s, char ch, size_t len);
|
||||
|
||||
void strbuf_rchop(strbuf_t *s, char ch);
|
||||
|
||||
void strbuf_term(strbuf_t *s, char ch);
|
||||
|
|
|
|||
|
|
@ -105,14 +105,14 @@ void test_trim() {
|
|||
|
||||
print_strbuf(&b);
|
||||
|
||||
strbuf_append(&b, " ", 4);
|
||||
strbuf_append_repeat(&b, ' ', 4);
|
||||
strbuf_append(&b, "abcdef", 6);
|
||||
|
||||
print_strbuf(&b);
|
||||
|
||||
strbuf_append(&b, "012345678901234567890123456789", 30);
|
||||
strbuf_append_ch(&b, 'a');
|
||||
strbuf_append_str(&b, " ");
|
||||
strbuf_append_repeat(&b, ' ', 6);
|
||||
|
||||
print_strbuf(&b);
|
||||
|
||||
|
|
|
|||
Reference in a new issue