unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v4 0/5] Use Xapian query syntax for batch-tag dump/restore
@ 2012-12-31  6:42 Austin Clements
  2012-12-31  6:42 ` [PATCH v4 1/5] util: Factor out boolean term quoting routine Austin Clements
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Austin Clements @ 2012-12-31  6:42 UTC (permalink / raw)
  To: notmuch; +Cc: tomi.ollila

This obsoletes

  id:1356719189-2837-1-git-send-email-amdragon@mit.edu

This version accepts whitespace before and after boolean terms in
parse_boolean_term and expands its documentation comment to describe
what it accepts and how that relates to Xapian and make_boolean_term.

The diff from v3 is below.

diff --git a/util/string-util.c b/util/string-util.c
index 83b4953..52c7781 100644
--- a/util/string-util.c
+++ b/util/string-util.c
@@ -22,6 +22,8 @@
 #include "string-util.h"
 #include "talloc.h"
 
+#include <ctype.h>
+
 char *
 strtok_len (char *s, const char *delim, size_t *len)
 {
@@ -97,6 +99,14 @@ make_boolean_term (void *ctx, const char *prefix, const char *term,
     return 0;
 }
 
+static const char*
+skip_space (const char *str)
+{
+    while (*str && isspace (*str))
+	++str;
+    return str;
+}
+
 int
 parse_boolean_term (void *ctx, const char *str,
 		    char **prefix_out, char **term_out)
@@ -104,6 +114,7 @@ parse_boolean_term (void *ctx, const char *str,
     *prefix_out = *term_out = NULL;
 
     /* Parse prefix */
+    str = skip_space (str);
     const char *pos = strchr (str, ':');
     if (! pos)
 	goto FAIL;
@@ -123,6 +134,7 @@ parse_boolean_term (void *ctx, const char *str,
 		if (*pos != '"') {
 		    /* Found the closing quote. */
 		    closed = 1;
+		    pos = skip_space (pos);
 		    break;
 		}
 	    }
@@ -138,11 +150,11 @@ parse_boolean_term (void *ctx, const char *str,
 	/* Check for text after the boolean term. */
 	while (*pos > ' ' && *pos != ')')
 	    ++pos;
-	if (*pos)
+	if (*skip_space (pos))
 	    goto FAIL;
 	/* No trailing text; dup the string so the caller can free
 	 * it. */
-	*term_out = talloc_strdup (ctx, start);
+	*term_out = talloc_strndup (ctx, start, pos - start);
     }
     return 0;
 
diff --git a/util/string-util.h b/util/string-util.h
index 43d49d0..8b9fe50 100644
--- a/util/string-util.h
+++ b/util/string-util.h
@@ -33,12 +33,16 @@ char *strtok_len (char *s, const char *delim, size_t *len);
 int make_boolean_term (void *talloc_ctx, const char *prefix, const char *term,
 		       char **buf, size_t *len);
 
-/* Parse a boolean term query produced by make_boolean_term, returning
- * the prefix in *prefix_out and the term in *term_out.  *prefix_out
- * and *term_out will be talloc'd with context ctx.
+/* Parse a boolean term query consisting of a prefix, a colon, and a
+ * term that may be quoted as described for make_boolean_term.  If the
+ * term is not quoted, then it ends at the first whitespace or close
+ * parenthesis.  str may containing leading or trailing whitespace,
+ * but anything else is considered a parse error.  This is compatible
+ * with anything produced by make_boolean_term, and supports a subset
+ * of the quoting styles supported by Xapian (and hence notmuch).
+ * *prefix_out and *term_out will be talloc'd with context ctx.
  *
- * Return: 0 on success, non-zero on parse error (including trailing
- * data in str).
+ * Return: 0 on success, non-zero on parse error.
  */
 int
 parse_boolean_term (void *ctx, const char *str,
  

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-01-04  7:27 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-31  6:42 [PATCH v4 0/5] Use Xapian query syntax for batch-tag dump/restore Austin Clements
2012-12-31  6:42 ` [PATCH v4 1/5] util: Factor out boolean term quoting routine Austin Clements
2013-01-03 16:48   ` Jani Nikula
2013-01-04  7:26     ` Austin Clements
2012-12-31  6:42 ` [PATCH v4 2/5] util: Function to parse boolean term queries Austin Clements
2012-12-31 12:01   ` Mark Walters
2013-01-03 17:09   ` Jani Nikula
2012-12-31  6:42 ` [PATCH v4 3/5] dump: Disallow \n in message IDs Austin Clements
2013-01-03 17:19   ` Jani Nikula
2012-12-31  6:42 ` [PATCH v4 4/5] dump/restore: Use Xapian queries for batch-tag format Austin Clements
2012-12-31 12:41   ` Mark Walters
2012-12-31 16:52     ` David Bremner
2012-12-31  6:42 ` [PATCH v4 5/5] man: Update notmuch-dump(1) and notmuch-restore(1) Austin Clements
2012-12-31 22:14 ` [PATCH v4 0/5] Use Xapian query syntax for batch-tag dump/restore Tomi Ollila

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

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 read-only IMAP folder(s) and NNTP newsgroup(s).