[Patch v9 05/17] util/string-util: add a new string tokenized function
authordavid <david@tethera.net>
Mon, 24 Dec 2012 01:39:31 +0000 (21:39 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:39 +0000 (09:52 -0800)
a1/deb229086436cef68f020b2fbd3178d94a69d5 [new file with mode: 0644]

diff --git a/a1/deb229086436cef68f020b2fbd3178d94a69d5 b/a1/deb229086436cef68f020b2fbd3178d94a69d5
new file mode 100644 (file)
index 0000000..6e7bf62
--- /dev/null
@@ -0,0 +1,121 @@
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id F1B29431FDA\r
+       for <notmuch@notmuchmail.org>; Sun, 23 Dec 2012 17:40:06 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id M0Pd0owaUDqa for <notmuch@notmuchmail.org>;\r
+       Sun, 23 Dec 2012 17:40:06 -0800 (PST)\r
+Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
+       (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 730B9431FBC\r
+       for <notmuch@notmuchmail.org>; Sun, 23 Dec 2012 17:40:02 -0800 (PST)\r
+Received: from fctnnbsc30w-156034082078.dhcp-dynamic.fibreop.nb.bellaliant.net\r
+       ([156.34.82.78] helo=zancas.localnet)\r
+       by tesseract.cs.unb.ca with esmtpsa\r
+       (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)\r
+       (envelope-from <bremner@tethera.net>)\r
+       id 1Tmx1L-0008Ko-Rl; Sun, 23 Dec 2012 21:40:00 -0400\r
+Received: from bremner by zancas.localnet with local (Exim 4.80)\r
+       (envelope-from <bremner@tethera.net>)\r
+       id 1Tmx1G-0002nb-AV; Sun, 23 Dec 2012 21:39:54 -0400\r
+From: david@tethera.net\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v9 05/17] util/string-util: add a new string tokenized\r
+ function\r
+Date: Sun, 23 Dec 2012 21:39:31 -0400\r
+Message-Id: <1356313183-9266-6-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1356313183-9266-1-git-send-email-david@tethera.net>\r
+References: <1356313183-9266-1-git-send-email-david@tethera.net>\r
+X-Spam_bar: -\r
+Cc: David Bremner <bremner@debian.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 24 Dec 2012 01:40:07 -0000\r
+\r
+From: David Bremner <bremner@debian.org>\r
+\r
+This initial target use is in quoting queries for Xapian. We want to\r
+split into tokens, but preserve the delimiters between the tokens\r
+verbatim.\r
+---\r
+ util/string-util.c |   12 ++++++++++++\r
+ util/string-util.h |   19 +++++++++++++++++++\r
+ 2 files changed, 31 insertions(+)\r
+\r
+diff --git a/util/string-util.c b/util/string-util.c\r
+index b9039f4..1586483 100644\r
+--- a/util/string-util.c\r
++++ b/util/string-util.c\r
+@@ -34,6 +34,18 @@ strtok_len (char *s, const char *delim, size_t *len)\r
+     return *len ? s : NULL;\r
+ }\r
\r
++char *\r
++strtok_len2 (char *s, const char *delim, size_t *len, size_t *delim_len)\r
++{\r
++    /* length of token */\r
++    *len = strcspn (s, delim);\r
++\r
++    /* length of following delimiter */\r
++    *delim_len = strspn (s + *len, delim);\r
++\r
++    return *len || *delim_len ? s : NULL;\r
++}\r
++\r
\r
+ int\r
+ double_quote_str (void *ctx, const char *str,\r
+diff --git a/util/string-util.h b/util/string-util.h\r
+index 4fc7942..12398a5 100644\r
+--- a/util/string-util.h\r
++++ b/util/string-util.h\r
+@@ -19,6 +19,25 @@\r
\r
+ char *strtok_len (char *s, const char *delim, size_t *len);\r
\r
++/* Like strtok_len, but return length of delimiters as well.  Return\r
++ * value is indicated by pointer and length, not null terminator.\r
++ * Does _not_ skip initial delimiters.\r
++ *\r
++ * Usage pattern:\r
++ *\r
++ * const char *tok = input;\r
++ * const char *delim = " :.,";\r
++ * size_t tok_len = 0;\r
++ * size_t delim_len = 0;\r
++ *\r
++ * while ((tok = strtok_len (tok + tok_len + delim_len, delim,\r
++ *                         &tok_len, &delim_len)) != NULL) {\r
++ *     // do stuff with token and following delimiters.\r
++ * }\r
++ */\r
++\r
++char *strtok_len2 (char *s, const char *delim, size_t *len, size_t *delim_len);\r
++\r
+ /* Copy str to dest, surrounding with double quotes.\r
+  * Any internal double-quotes are doubled, i.e. a"b -> "a""b"\r
+  *\r
+-- \r
+1.7.10.4\r
+\r