Archived
1
0
Fork 0

strbuf.c: Added strbuf_append_repeat function

This commit is contained in:
Henrik Hautakoski 2010-11-19 11:04:16 +01:00
parent 0416fea36a
commit f06a528ad0
3 changed files with 12 additions and 2 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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);