From: Christian Couder <chriscool@tuxfamily.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
John Tapsell <johnflux@gmail.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Pierre Habouzit <madcoder@debian.org>
Subject: [PATCH 1/7] strbuf: add "include_delim" parameter to "strbuf_split"
Date: Thu, 12 Mar 2009 08:51:03 +0100 [thread overview]
Message-ID: <20090312085103.e83b34a5.chriscool@tuxfamily.org> (raw)
The "strbuf_split" function used to include the delimiter character
at the end of the splited strbufs it produced.
This behavior is not wanted in many cases, so this patch adds a new
"include_delim" parameter to the function to let us switch it on or
off as we want.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin-mailinfo.c | 2 +-
imap-send.c | 2 +-
strbuf.c | 8 +++++---
strbuf.h | 2 +-
4 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index 2789ccd..b96ea1a 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -814,7 +814,7 @@ static void handle_body(void)
* multiple new lines. Pass only one chunk
* at a time to handle_filter()
*/
- lines = strbuf_split(&line, '\n');
+ lines = strbuf_split(&line, '\n', 1);
for (it = lines; (sb = *it); it++) {
if (*(it + 1) == NULL) /* The last line */
if (sb->buf[sb->len - 1] != '\n') {
diff --git a/imap-send.c b/imap-send.c
index cb518eb..a27f744 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1289,7 +1289,7 @@ static void wrap_in_html(struct msg_data *msg)
int added_header = 0;
strbuf_attach(&buf, msg->data, msg->len, msg->len);
- lines = strbuf_split(&buf, '\n');
+ lines = strbuf_split(&buf, '\n', 1);
strbuf_release(&buf);
for (p = lines; *p; p++) {
if (! added_header) {
diff --git a/strbuf.c b/strbuf.c
index 6ed0684..4ef9084 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -97,7 +97,9 @@ void strbuf_tolower(struct strbuf *sb)
sb->buf[i] = tolower(sb->buf[i]);
}
-struct strbuf **strbuf_split(const struct strbuf *sb, int delim)
+struct strbuf **strbuf_split(const struct strbuf *sb,
+ int delim,
+ int include_delim)
{
int alloc = 2, pos = 0;
char *n, *p;
@@ -114,8 +116,8 @@ struct strbuf **strbuf_split(const struct strbuf *sb, int delim)
ret = xrealloc(ret, sizeof(struct strbuf *) * alloc);
}
if (!n)
- n = sb->buf + sb->len - 1;
- len = n - p + 1;
+ n = sb->buf + sb->len - (include_delim ? 1 : 0);
+ len = n - p + (include_delim ? 1 : 0);
t = xmalloc(sizeof(struct strbuf));
strbuf_init(t, len);
strbuf_add(t, p, len);
diff --git a/strbuf.h b/strbuf.h
index 89bd36e..2202d28 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -83,7 +83,7 @@ extern void strbuf_ltrim(struct strbuf *);
extern int strbuf_cmp(const struct strbuf *, const struct strbuf *);
extern void strbuf_tolower(struct strbuf *);
-extern struct strbuf **strbuf_split(const struct strbuf *, int delim);
+extern struct strbuf **strbuf_split(const struct strbuf *, int delim, int include_delim);
extern void strbuf_list_free(struct strbuf **);
/*----- add data in your buffer -----*/
--
1.6.2.83.g012a16.dirty
next reply other threads:[~2009-03-12 7:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-12 7:51 Christian Couder [this message]
[not found] ` <20090312190846.6117@nanako3.lavabit.com>
2009-03-13 4:48 ` [PATCH 1/7] strbuf: add "include_delim" parameter to "strbuf_split" Christian Couder
2009-03-13 5:17 ` Junio C Hamano
2009-03-13 6:02 ` Christian Couder
2009-03-13 6:53 ` Junio C Hamano
2009-03-14 7:46 ` Migrate bisect to C (was: [PATCH 1/7] strbuf: add "include_delim" parameter to "strbuf_split") Christian Couder
2009-03-14 8:16 ` Migrate bisect to C Junio C Hamano
2009-03-14 12:09 ` fetch--tool, was " Johannes Schindelin
2009-03-13 7:06 ` [PATCH 1/7] strbuf: add "include_delim" parameter to "strbuf_split" 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=20090312085103.e83b34a5.chriscool@tuxfamily.org \
--to=chriscool@tuxfamily.org \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johnflux@gmail.com \
--cc=madcoder@debian.org \
--cc=mingo@elte.hu \
/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).