Skip to content

Commit

Permalink
strbuf: export strbuf_addchars()
Browse files Browse the repository at this point in the history
Move strbuf_addchars() to strbuf.c, where it belongs, and make it
available for other callers.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Sep 8, 2014
1 parent e6aaa39 commit d07235a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Documentation/technical/api-strbuf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ then they will free() it.

Add a single character to the buffer.

`strbuf_addchars`::

Add a character the specified number of times to the buffer.

`strbuf_insert`::

Insert data to the given position of the buffer. The remaining contents
Expand Down
7 changes: 7 additions & 0 deletions strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len)
strbuf_setlen(sb, sb->len + len);
}

void strbuf_addchars(struct strbuf *sb, int c, size_t n)
{
strbuf_grow(sb, n);
memset(sb->buf + sb->len, c, n);
strbuf_setlen(sb, sb->len + n);
}

void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
{
va_list ap;
Expand Down
1 change: 1 addition & 0 deletions strbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ static inline void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2) {
strbuf_add(sb, sb2->buf, sb2->len);
}
extern void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len);
extern void strbuf_addchars(struct strbuf *sb, int c, size_t n);

typedef size_t (*expand_fn_t) (struct strbuf *sb, const char *placeholder, void *context);
extern void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn, void *context);
Expand Down
7 changes: 0 additions & 7 deletions utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,6 @@ int is_utf8(const char *text)
return 1;
}

static void strbuf_addchars(struct strbuf *sb, int c, size_t n)
{
strbuf_grow(sb, n);
memset(sb->buf + sb->len, c, n);
strbuf_setlen(sb, sb->len + n);
}

static void strbuf_add_indented_text(struct strbuf *buf, const char *text,
int indent, int indent2)
{
Expand Down

0 comments on commit d07235a

Please sign in to comment.