From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 08B3E431FAF for ; Sat, 22 Dec 2012 18:59:44 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ARuTOxAfawyg for ; Sat, 22 Dec 2012 18:59:44 -0800 (PST) Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 59FD6431FAE for ; Sat, 22 Dec 2012 18:59:44 -0800 (PST) Received: from fctnnbsc30w-156034082078.dhcp-dynamic.fibreop.nb.bellaliant.net ([156.34.82.78] helo=zancas.localnet) by tesseract.cs.unb.ca with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1Tmbmu-0007XI-VO; Sat, 22 Dec 2012 22:59:41 -0400 Received: from bremner by zancas.localnet with local (Exim 4.80) (envelope-from ) id 1Tmbmn-0007SI-0t; Sat, 22 Dec 2012 22:59:33 -0400 From: david@tethera.net To: notmuch@notmuchmail.org Subject: [PATCH] simplify unhex_and_quote Date: Sat, 22 Dec 2012 22:59:30 -0400 Message-Id: <1356231570-28232-1-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <87txrdhd7g.fsf@oiva.home.nikula.org> References: <87txrdhd7g.fsf@oiva.home.nikula.org> X-Spam_bar: - Cc: David Bremner X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Dec 2012 02:59:45 -0000 From: David Bremner the overgeneral definition of a prefix can be replaced by lower case alphabetic, and still work fine with current notmuch query syntax. token_len++ is moved to the end, and we restore the delimiter just so we can leave the string as as we found it. --- As always, Jani has a keen eye for muddle. Except he's wrong about tok_len - prefix_len, and Mark and I are right. Hopefully ;). Restoring the delimiter at the end might be pointless (since the rest of the input line is modified), but it is one less surprise for somebody repurposing the function. Patches 5 and 6 can be ignored now. tag-util.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tag-util.c b/tag-util.c index b0a846b..ee28512 100644 --- a/tag-util.c +++ b/tag-util.c @@ -78,11 +78,13 @@ unhex_and_quote (void *ctx, char *encoded, const char *line_for_error, size_t prefix_len; char delim = *(tok + tok_len); - *(tok + tok_len++) = '\0'; + *(tok + tok_len) = '\0'; - prefix_len = hex_invariant (tok, tok_len); + /* The following matches a superset of prefixes currently + * used by notmuch */ + prefix_len = strspn (tok, "abcdefghijklmnopqrstuvwxyz"); - if ((strcmp (tok, "*") == 0) || prefix_len >= tok_len - 1) { + if ((strcmp (tok, "*") == 0) || prefix_len == tok_len) { /* pass some things through without quoting or decoding. * Note for '*' this is mandatory. @@ -98,7 +100,7 @@ unhex_and_quote (void *ctx, char *encoded, const char *line_for_error, } else { /* potential prefix: one for ':', then something after */ - if ((tok_len - prefix_len > 2) && *(tok + prefix_len) == ':') { + if ((tok_len - prefix_len >= 2) && *(tok + prefix_len) == ':') { if (! (*query_string = talloc_strndup_append (*query_string, tok, prefix_len + 1))) { @@ -129,6 +131,8 @@ unhex_and_quote (void *ctx, char *encoded, const char *line_for_error, goto DONE; } } + /* restore the string and skip delimiter */ + *(tok + tok_len++) = delim; } DONE: -- 1.7.10.4