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>
This commit is contained in:
René Scharfe 2010-02-19 23:15:55 +01:00 коммит произвёл Junio C Hamano
Родитель bb96a2c900
Коммит 3c0ff44a1e
1 изменённых файлов: 6 добавлений и 9 удалений

15
utf8.c
Просмотреть файл

@ -288,14 +288,11 @@ static inline void strbuf_write(struct strbuf *sb, const char *buf, int len)
fwrite(buf, len, 1, stdout); 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[] = " "; strbuf_grow(sb, n);
while (count >= sizeof(s)) { memset(sb->buf + sb->len, c, n);
strbuf_write(buf, s, sizeof(s) - 1); strbuf_setlen(sb, sb->len + n);
count -= sizeof(s) - 1;
}
strbuf_write(buf, s, count);
} }
static void strbuf_add_indented_text(struct strbuf *buf, const char *text, 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'); const char *eol = strchrnul(text, '\n');
if (*eol == '\n') if (*eol == '\n')
eol++; eol++;
print_spaces(buf, indent); strbuf_addchars(buf, ' ', indent);
strbuf_write(buf, text, eol - text); strbuf_write(buf, text, eol - text);
text = eol; text = eol;
indent = indent2; indent = indent2;
@ -366,7 +363,7 @@ int strbuf_add_wrapped_text(struct strbuf *buf,
if (space) if (space)
start = space; start = space;
else else
print_spaces(buf, indent); strbuf_addchars(buf, ' ', indent);
strbuf_write(buf, start, text - start); strbuf_write(buf, start, text - start);
if (!c) if (!c)
return w; return w;