summaryrefslogtreecommitdiff
path: root/utf8.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2010-02-19 23:15:55 +0100
committerJunio C Hamano <gitster@pobox.com>2010-02-20 09:19:06 -0800
commit3c0ff44a1ee92bd0f811b95d747a08763983566b (patch)
tree28b09ae0d72c4d8a6f601ace3831f6ddf260e074 /utf8.c
parentbb96a2c9005f925b4e80ece0a7cd6230f7f4b43d (diff)
downloadgit-3c0ff44a1ee92bd0f811b95d747a08763983566b.tar.gz
utf8.c: remove print_spaces()
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>
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/utf8.c b/utf8.c
index 5c8a2697f3..a4e36ff33c 100644
--- a/utf8.c
+++ b/utf8.c
@@ -288,14 +288,11 @@ static inline void strbuf_write(struct strbuf *sb, const char *buf, int len)
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,
@@ -307,7 +304,7 @@ 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;
@@ -366,7 +363,7 @@ int strbuf_add_wrapped_text(struct strbuf *buf,
if (space)
start = space;
else
- print_spaces(buf, indent);
+ strbuf_addchars(buf, ' ', indent);
strbuf_write(buf, start, text - start);
if (!c)
return w;