1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-07 01:06:09 +02:00

strbuf: add fixed-length version of add_wrapped_text

The function strbuf_add_wrapped_text takes a NUL-terminated
string. This makes it annoying to wrap strings we have as a
pointer and a length.

Refactoring strbuf_add_wrapped_text and all of its
sub-functions to handle fixed-length strings turned out to
be really ugly. So this implementation is lame; it just
strdups the text and operates on the NUL-terminated version.
This should be fine as the strings we are wrapping are
generally pretty short.  If it becomes a problem, we can
optimize later.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2011-02-23 04:50:19 -05:00 committed by Junio C Hamano
parent 7ed863a85a
commit 98acc837a1
2 changed files with 11 additions and 0 deletions

9
utf8.c
View File

@ -405,6 +405,15 @@ int strbuf_add_wrapped_text(struct strbuf *buf,
}
}
int strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len,
int indent, int indent2, int width)
{
char *tmp = xstrndup(data, len);
int r = strbuf_add_wrapped_text(buf, tmp, indent, indent2, width);
free(tmp);
return r;
}
int is_encoding_utf8(const char *name)
{
if (!name)

2
utf8.h
View File

@ -10,6 +10,8 @@ int is_encoding_utf8(const char *name);
int strbuf_add_wrapped_text(struct strbuf *buf,
const char *text, int indent, int indent2, int width);
int strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len,
int indent, int indent2, int width);
#ifndef NO_ICONV
char *reencode_string(const char *in, const char *out_encoding, const char *in_encoding);