From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: xzer <xiaozhu@gmail.com>, git@vger.kernel.org
Subject: [PATCH 1/3] strbuf: add fixed-length version of add_wrapped_text
Date: Wed, 23 Feb 2011 04:50:19 -0500 [thread overview]
Message-ID: <20110223095018.GA9222@sigill.intra.peff.net> (raw)
In-Reply-To: <20110223094844.GA9205@sigill.intra.peff.net>
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>
---
utf8.c | 9 +++++++++
utf8.h | 2 ++
2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/utf8.c b/utf8.c
index 84cfc72..8acbc66 100644
--- a/utf8.c
+++ b/utf8.c
@@ -405,6 +405,15 @@ new_line:
}
}
+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)
diff --git a/utf8.h b/utf8.h
index ebc4d2f..81f2c82 100644
--- a/utf8.h
+++ b/utf8.h
@@ -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);
--
1.7.2.5.15.gfdd1c
next prev parent reply other threads:[~2011-02-23 9:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-14 8:09 [PATCH] generate a valid rfc2047 mail header for multi-line subject xzer
2011-02-22 20:43 ` Junio C Hamano
2011-02-23 8:08 ` Jeff King
2011-02-23 9:48 ` Jeff King
2011-02-23 9:50 ` Jeff King [this message]
2011-02-23 9:58 ` [PATCH 2/3] format-patch: wrap long header lines Jeff King
2011-02-23 9:59 ` [PATCH 3/3] format-patch: rfc2047-encode newlines in headers Jeff King
2011-02-23 21:47 ` Junio C Hamano
2011-02-24 7:15 ` Jeff King
2011-02-23 15:16 ` [PATCH] generate a valid rfc2047 mail header for multi-line subject xzer
2011-02-23 16:35 ` Jeff King
2011-02-23 17:34 ` Junio C Hamano
2011-02-24 7:34 ` Jeff King
2011-02-23 15:34 ` xzer
2011-02-23 17:45 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110223095018.GA9222@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=xiaozhu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).