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>
Jeff King committed
Feb 23, 2011 at 04:50 UTC
98acc837a14c2ab1975b38b93cb028e87e47ad4a
2 files changed
+11
utf8.c
+9
@@ -405,6 +405,15 @@ new_line:
405
}
406
}
407
408
+int strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len,
409
+ int indent, int indent2, int width)
410
+{
411
+ char *tmp = xstrndup(data, len);
412
+ int r = strbuf_add_wrapped_text(buf, tmp, indent, indent2, width);
413
+ free(tmp);
414
+ return r;
415
+}
416
+
417
int is_encoding_utf8(const char *name)
418
{
419
if (!name)
utf8.h
+2
@@ -10,6 +10,8 @@ int is_encoding_utf8(const char *name);
10
11
int strbuf_add_wrapped_text(struct strbuf *buf,
12
const char *text, int indent, int indent2, int width);
13
+int strbuf_add_wrapped_bytes(struct strbuf *buf, const char *data, int len,
14
+ int indent, int indent2, int width);
15
16
#ifndef NO_ICONV
17
char *reencode_string(const char *in, const char *out_encoding, const char *in_encoding);