1 Return-Path: <bremner@tethera.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id F1B29431FDA
\r
6 for <notmuch@notmuchmail.org>; Sun, 23 Dec 2012 17:40:06 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id M0Pd0owaUDqa for <notmuch@notmuchmail.org>;
\r
16 Sun, 23 Dec 2012 17:40:06 -0800 (PST)
\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])
\r
18 (using TLSv1 with cipher AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 730B9431FBC
\r
21 for <notmuch@notmuchmail.org>; Sun, 23 Dec 2012 17:40:02 -0800 (PST)
\r
22 Received: from fctnnbsc30w-156034082078.dhcp-dynamic.fibreop.nb.bellaliant.net
\r
23 ([156.34.82.78] helo=zancas.localnet)
\r
24 by tesseract.cs.unb.ca with esmtpsa
\r
25 (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)
\r
26 (envelope-from <bremner@tethera.net>)
\r
27 id 1Tmx1L-0008Ko-Rl; Sun, 23 Dec 2012 21:40:00 -0400
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1Tmx1G-0002nb-AV; Sun, 23 Dec 2012 21:39:54 -0400
\r
31 From: david@tethera.net
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [Patch v9 05/17] util/string-util: add a new string tokenized
\r
35 Date: Sun, 23 Dec 2012 21:39:31 -0400
\r
36 Message-Id: <1356313183-9266-6-git-send-email-david@tethera.net>
\r
37 X-Mailer: git-send-email 1.7.10.4
\r
38 In-Reply-To: <1356313183-9266-1-git-send-email-david@tethera.net>
\r
39 References: <1356313183-9266-1-git-send-email-david@tethera.net>
\r
41 Cc: David Bremner <bremner@debian.org>
\r
42 X-BeenThere: notmuch@notmuchmail.org
\r
43 X-Mailman-Version: 2.1.13
\r
45 List-Id: "Use and development of the notmuch mail system."
\r
46 <notmuch.notmuchmail.org>
\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
50 List-Post: <mailto:notmuch@notmuchmail.org>
\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
54 X-List-Received-Date: Mon, 24 Dec 2012 01:40:07 -0000
\r
56 From: David Bremner <bremner@debian.org>
\r
58 This initial target use is in quoting queries for Xapian. We want to
\r
59 split into tokens, but preserve the delimiters between the tokens
\r
62 util/string-util.c | 12 ++++++++++++
\r
63 util/string-util.h | 19 +++++++++++++++++++
\r
64 2 files changed, 31 insertions(+)
\r
66 diff --git a/util/string-util.c b/util/string-util.c
\r
67 index b9039f4..1586483 100644
\r
68 --- a/util/string-util.c
\r
69 +++ b/util/string-util.c
\r
70 @@ -34,6 +34,18 @@ strtok_len (char *s, const char *delim, size_t *len)
\r
71 return *len ? s : NULL;
\r
75 +strtok_len2 (char *s, const char *delim, size_t *len, size_t *delim_len)
\r
77 + /* length of token */
\r
78 + *len = strcspn (s, delim);
\r
80 + /* length of following delimiter */
\r
81 + *delim_len = strspn (s + *len, delim);
\r
83 + return *len || *delim_len ? s : NULL;
\r
88 double_quote_str (void *ctx, const char *str,
\r
89 diff --git a/util/string-util.h b/util/string-util.h
\r
90 index 4fc7942..12398a5 100644
\r
91 --- a/util/string-util.h
\r
92 +++ b/util/string-util.h
\r
95 char *strtok_len (char *s, const char *delim, size_t *len);
\r
97 +/* Like strtok_len, but return length of delimiters as well. Return
\r
98 + * value is indicated by pointer and length, not null terminator.
\r
99 + * Does _not_ skip initial delimiters.
\r
103 + * const char *tok = input;
\r
104 + * const char *delim = " :.,";
\r
105 + * size_t tok_len = 0;
\r
106 + * size_t delim_len = 0;
\r
108 + * while ((tok = strtok_len (tok + tok_len + delim_len, delim,
\r
109 + * &tok_len, &delim_len)) != NULL) {
\r
110 + * // do stuff with token and following delimiters.
\r
114 +char *strtok_len2 (char *s, const char *delim, size_t *len, size_t *delim_len);
\r
116 /* Copy str to dest, surrounding with double quotes.
\r
117 * Any internal double-quotes are doubled, i.e. a"b -> "a""b"
\r