summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bb96a2c)
raw | patch | inline | side by side (parent: bb96a2c)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Fri, 19 Feb 2010 22:15:55 +0000 (23:15 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 20 Feb 2010 17:19:06 +0000 (09:19 -0800) |
The previous patch made sure that strbuf_add_wrapped_text() (and thus
strbuf_add_indented_text(), too) always get a strbuf. Make use of
this fact by adding strbuf_addchars(), a small helper that adds a
char the specified number of times to a strbuf, and use it to replace
print_spaces().
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
strbuf_add_indented_text(), too) always get a strbuf. Make use of
this fact by adding strbuf_addchars(), a small helper that adds a
char the specified number of times to a strbuf, and use it to replace
print_spaces().
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
utf8.c | patch | blob | history |
index 5c8a2697f3cceacaa3dff2ea1c7ff9379e280285..a4e36ff33c4b7df768c3802f5278c3847c7810c1 100644 (file)
--- a/utf8.c
+++ b/utf8.c
fwrite(buf, len, 1, stdout);
}
-static void print_spaces(struct strbuf *buf, int count)
+static void strbuf_addchars(struct strbuf *sb, int c, size_t n)
{
- static const char s[] = " ";
- while (count >= sizeof(s)) {
- strbuf_write(buf, s, sizeof(s) - 1);
- count -= sizeof(s) - 1;
- }
- strbuf_write(buf, s, count);
+ 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,
const char *eol = strchrnul(text, '\n');
if (*eol == '\n')
eol++;
- print_spaces(buf, indent);
+ strbuf_addchars(buf, ' ', indent);
strbuf_write(buf, text, eol - text);
text = eol;
indent = indent2;
if (space)
start = space;
else
- print_spaces(buf, indent);
+ strbuf_addchars(buf, ' ', indent);
strbuf_write(buf, start, text - start);
if (!c)
return w;