From 17e37f7f450bbfbf98fe1193547bd37886ac528b Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Thu, 3 Sep 2015 22:40:01 +0300 Subject: [PATCH] [PATCH v2 5/9] util: move strcase_equal and strcase_hash to util --- 54/96fef7b6abe11a5cfb0e70f867d79fbc5d5f63 | 170 ++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 54/96fef7b6abe11a5cfb0e70f867d79fbc5d5f63 diff --git a/54/96fef7b6abe11a5cfb0e70f867d79fbc5d5f63 b/54/96fef7b6abe11a5cfb0e70f867d79fbc5d5f63 new file mode 100644 index 000000000..15089e8db --- /dev/null +++ b/54/96fef7b6abe11a5cfb0e70f867d79fbc5d5f63 @@ -0,0 +1,170 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 218AB6DE1B56 + for ; Thu, 3 Sep 2015 12:40:35 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.424 +X-Spam-Level: +X-Spam-Status: No, score=-0.424 tagged_above=-999 required=5 tests=[AWL=0.296, + RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] + autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id oVAmmC1pzGg2 for ; + Thu, 3 Sep 2015 12:40:33 -0700 (PDT) +Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com + [209.85.212.175]) + by arlo.cworth.org (Postfix) with ESMTPS id 48C726DE15D4 + for ; Thu, 3 Sep 2015 12:40:25 -0700 (PDT) +Received: by wicfx3 with SMTP id fx3so1166855wic.1 + for ; Thu, 03 Sep 2015 12:40:23 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references:in-reply-to:references; + bh=VFHDC72I5GoT6PKzmB1izsWZDFNqN7WikG58dF2ZAyA=; + b=Ps+CaFqXd/i7ebRBM5SrMy4r3HhVaYRuOtHYp0YnFjYZqBtwynuf/NQ20cnylJ2dFJ + LDLNC4dCQ/Dq3DTifXnGRU6ReRza1NOHXzcZ4DPFlsjKgtJXmUT+LzUG6vrgutyRuwvN + 9+ARdBljQwKDy2ro585EOEBf4oa0qD0fpZCmrTqnFPCxg89FDIp5KtDCgIyZ0HlkCFcH + WUAAkWhBdwRq6gTmLUWY6CG1Ag5CSHHy8XMBarmR9khweimDf51wyD+I0IJ+F08D9mUe + ugmX/+Dvw1KqhtD3ToQyfaLuPgcL0GfvaIQeRsF4LKEdHdd7LLEWuyZmoqI1Q2vQ6lRF + HQRA== +X-Gm-Message-State: + ALoCoQnctlhEIgLHVm97wQbCXg5hYPxqWgUS+ii01EMGL8dA2PepdsayrlJXQ2drPpi7dH0hUow8 +X-Received: by 10.180.87.71 with SMTP id v7mr17872859wiz.74.1441309223852; + Thu, 03 Sep 2015 12:40:23 -0700 (PDT) +Received: from localhost (mobile-access-bcee4f-131.dhcp.inet.fi. + [188.238.79.131]) + by smtp.gmail.com with ESMTPSA id eu2sm639314wic.8.2015.09.03.12.40.23 + (version=TLSv1/SSLv3 cipher=OTHER); + Thu, 03 Sep 2015 12:40:23 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH v2 5/9] util: move strcase_equal and strcase_hash to util +Date: Thu, 3 Sep 2015 22:40:01 +0300 +Message-Id: + <37a90b2c8ac540599daf0e864b2a6b65b4ee35a3.1441308761.git.jani@nikula.org> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: +References: +In-Reply-To: +References: +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +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: Thu, 03 Sep 2015 19:40:35 -0000 + +For future use in both cli and lib. +--- + lib/message-file.c | 21 --------------------- + lib/notmuch-private.h | 1 + + util/string-util.c | 21 +++++++++++++++++++++ + util/string-util.h | 6 ++++++ + 4 files changed, 28 insertions(+), 21 deletions(-) + +diff --git a/lib/message-file.c b/lib/message-file.c +index 8ac96e8e06a5..ee305202fffa 100644 +--- a/lib/message-file.c ++++ b/lib/message-file.c +@@ -38,27 +38,6 @@ struct _notmuch_message_file { + }; + + static int +-strcase_equal (const void *a, const void *b) +-{ +- return strcasecmp (a, b) == 0; +-} +- +-static unsigned int +-strcase_hash (const void *ptr) +-{ +- const char *s = ptr; +- +- /* This is the djb2 hash. */ +- unsigned int hash = 5381; +- while (s && *s) { +- hash = ((hash << 5) + hash) + tolower (*s); +- s++; +- } +- +- return hash; +-} +- +-static int + _notmuch_message_file_destructor (notmuch_message_file_t *message) + { + if (message->headers) +diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h +index f52b4e4776f9..5dd4770e9619 100644 +--- a/lib/notmuch-private.h ++++ b/lib/notmuch-private.h +@@ -50,6 +50,7 @@ NOTMUCH_BEGIN_DECLS + + #include "xutil.h" + #include "error_util.h" ++#include "string-util.h" + + #pragma GCC visibility push(hidden) + +diff --git a/util/string-util.c b/util/string-util.c +index a90501ee3e70..76c0b9025d0f 100644 +--- a/util/string-util.c ++++ b/util/string-util.c +@@ -221,3 +221,24 @@ parse_boolean_term (void *ctx, const char *str, + errno = err; + return -1; + } ++ ++int ++strcase_equal (const void *a, const void *b) ++{ ++ return strcasecmp (a, b) == 0; ++} ++ ++unsigned int ++strcase_hash (const void *ptr) ++{ ++ const char *s = ptr; ++ ++ /* This is the djb2 hash. */ ++ unsigned int hash = 5381; ++ while (s && *s) { ++ hash = ((hash << 5) + hash) + tolower (*s); ++ s++; ++ } ++ ++ return hash; ++} +diff --git a/util/string-util.h b/util/string-util.h +index e409cb3d2ab1..80d24d1c1053 100644 +--- a/util/string-util.h ++++ b/util/string-util.h +@@ -64,6 +64,12 @@ int + parse_boolean_term (void *ctx, const char *str, + char **prefix_out, char **term_out); + ++/* GLib GEqualFunc compatible strcasecmp wrapper */ ++int strcase_equal (const void *a, const void *b); ++ ++/* GLib GHashFunc compatible case insensitive hash function */ ++unsigned int strcase_hash (const void *ptr); ++ + #ifdef __cplusplus + } + #endif +-- +2.1.4 + -- 2.26.2