[evolution-data-server] camel-search-private cleanups.



commit 2f824908e664c8b00689229663749345166c9faa
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Dec 22 09:08:50 2012 -0500

    camel-search-private cleanups.

 camel/camel-search-private.c |   76 +++++++++++++++++++++++------------------
 camel/camel-search-private.h |   33 +++++++++++++-----
 2 files changed, 67 insertions(+), 42 deletions(-)
---
diff --git a/camel/camel-search-private.c b/camel/camel-search-private.c
index 9be6236..c7e1eeb 100644
--- a/camel/camel-search-private.c
+++ b/camel/camel-search-private.c
@@ -44,12 +44,13 @@
 
 /* builds the regex into pattern */
 /* taken from camel-folder-search, with added isregex & exception parameter */
-/* Basically, we build a new regex, either based on subset regex's, or substrings,
- * that can be executed once over the whoel body, to match anything suitable.
- * This is more efficient than multiple searches, and probably most (naive) strstr
- * implementations, over long content.
+/* Basically, we build a new regex, either based on subset regex's, or
+ * substrings, that can be executed once over the whoel body, to match
+ * anything suitable.  This is more efficient than multiple searches,
+ * and probably most (naive) strstr implementations, over long content.
  *
- * A small issue is that case-insenstivity wont work entirely correct for utf8 strings. */
+ * A small issue is that case-insenstivity won't work entirely correct
+ * for utf8 strings. */
 gint
 camel_search_build_match_regex (regex_t *pattern,
                                 camel_search_flags_t type,
@@ -62,7 +63,8 @@ camel_search_build_match_regex (regex_t *pattern,
 	gchar *word;
 	gint flags;
 
-	/* build a regex pattern we can use to match the words, we OR them together */
+	/* Build a regex pattern we can use to match the words,
+	 * we OR them together. */
 	if (argc > 1)
 		g_string_append_c (match, '(');
 	for (i = 0; i < argc; i++) {
@@ -72,10 +74,12 @@ camel_search_build_match_regex (regex_t *pattern,
 
 			word = argv[i]->value.string;
 			if (type & CAMEL_SEARCH_MATCH_REGEX) {
-				/* no need to escape because this should already be a valid regex */
+				/* No need to escape because this
+				 * should already be a valid regex. */
 				g_string_append (match, word);
 			} else {
-				/* escape any special chars (not sure if this list is complete) */
+				/* Escape any special chars (not
+				 * sure if this list is complete). */
 				if (type & CAMEL_SEARCH_MATCH_START)
 					g_string_append_c (match, '^');
 				while ((c = *word++)) {
@@ -101,8 +105,8 @@ camel_search_build_match_regex (regex_t *pattern,
 		flags |= REG_NEWLINE;
 	err = regcomp (pattern, match->str, flags);
 	if (err != 0) {
-		/* regerror gets called twice to get the full error string
-		 * length to do proper posix error reporting */
+		/* regerror gets called twice to get the full error
+		 * string length to do proper posix error reporting. */
 		gint len = regerror (err, pattern, NULL, 0);
 		gchar *buffer = g_malloc0 (len + 1);
 
@@ -172,9 +176,10 @@ header_soundex (const gchar *header,
 
 	soundexify (match, mcode);
 
-	/* split the header into words, and soundexify and compare each one */
-	/* FIXME: Should this convert to utf8, and split based on that, and what not?
-	 * soundex only makes sense for us-ascii though ... */
+	/* Split the header into words and soundexify and compare each one. */
+	/* FIXME: Should this convert to utf8, and split based on that,
+	 *        and what not?
+	 *        soundex only makes sense for us-ascii though ... */
 
 	word = g_string_new ("");
 	p = header;
@@ -218,7 +223,7 @@ camel_ustrstrcase (const gchar *haystack,
 	while ((u = camel_utf8_getc (&p)))
 		*puni++ = g_unichar_tolower (u);
 
-	/* NULL means there was illegal utf-8 sequence */
+	/* NULL means there was illegal utf-8 sequence. */
 	if (!p)
 		return NULL;
 
@@ -227,7 +232,7 @@ camel_ustrstrcase (const gchar *haystack,
 		gunichar c;
 
 		c = g_unichar_tolower (u);
-		/* We have valid stripped gchar */
+		/* We have valid stripped gchar. */
 		if (c == nuni[0]) {
 			const guchar *q = p;
 			gint npos = 1;
@@ -392,7 +397,7 @@ camel_ustrncasecmp (const gchar *ps1,
 	return 0;
 }
 
-/* value is the match value suitable for exact match if required */
+/* Value is the match value suitable for exact match if required. */
 static gint
 header_match (const gchar *value,
               const gchar *match,
@@ -426,8 +431,8 @@ header_match (const gchar *value,
 	return FALSE;
 }
 
-/* searhces for match inside value, if match is mixed case, hten use case-sensitive,
- * else insensitive */
+/* Searches for match inside value.  If match is mixed
+ * case, then use case-sensitive, else insensitive. */
 gboolean
 camel_search_header_match (const gchar *value,
                            const gchar *match,
@@ -448,15 +453,16 @@ camel_search_header_match (const gchar *value,
 
 	switch (type) {
 	case CAMEL_SEARCH_TYPE_ENCODED:
-		v = camel_header_decode_string (value, default_charset); /* FIXME: Find header charset */
+		/* FIXME Find header charset. */
+		v = camel_header_decode_string (value, default_charset);
 		truth = header_match (v, match, how);
 		g_free (v);
 		break;
 	case CAMEL_SEARCH_TYPE_MLIST:
-		/* Special mailing list old-version domain hack
-		 * If one of the mailing list names doesn't have an @ in it, its old-style, so
-		 * only match against the pre-domain part, which should be common */
-
+		/* Special mailing list old-version domain hack.
+		 * If one of the mailing list names doesn't have an @ in it,
+		 * its old-style, so only match against the pre-domain part,
+		 * which should be common. */
 		vdom = strchr (value, '@');
 		mdom = strchr (match, '@');
 		if (mdom == NULL && vdom != NULL) {
@@ -476,11 +482,12 @@ camel_search_header_match (const gchar *value,
 		break;
 	case CAMEL_SEARCH_TYPE_ADDRESS_ENCODED:
 	case CAMEL_SEARCH_TYPE_ADDRESS:
-		/* possible simple case to save some work if we can */
+		/* Possible simple case to save some work if we can. */
 		if (header_match (value, match, how))
 			return TRUE;
 
-		/* Now we decode any addresses, and try asis matches on name and address parts */
+		/* Now we decode any addresses, and try
+		 * as-is matches on name and address parts. */
 		cia = camel_internet_address_new ();
 		if (type == CAMEL_SEARCH_TYPE_ADDRESS_ENCODED)
 			camel_address_decode ((CamelAddress *) cia, value);
@@ -488,7 +495,9 @@ camel_search_header_match (const gchar *value,
 			camel_address_unformat ((CamelAddress *) cia, value);
 
 		for (i = 0; !truth && camel_internet_address_get (cia, i, &name, &addr); i++)
-			truth = (name && header_match (name, match, how)) || (addr && header_match (addr, match, how));
+			truth =
+				(name && header_match (name, match, how)) ||
+				(addr && header_match (addr, match, how));
 
 		g_object_unref (cia);
 		break;
@@ -497,8 +506,8 @@ camel_search_header_match (const gchar *value,
 	return truth;
 }
 
-/* performs a 'slow' content-based match */
-/* there is also an identical copy of this in camel-filter-search.c */
+/* Performs a 'slow' content-based match. */
+/* There is also an identical copy of this in camel-filter-search.c. */
 gboolean
 camel_search_message_body_contains (CamelDataWrapper *object,
                                     regex_t *pattern)
@@ -512,7 +521,7 @@ camel_search_message_body_contains (CamelDataWrapper *object,
 	if (containee == NULL)
 		return FALSE;
 
-	/* using the object types is more accurate than using the mime/types */
+	/* Using the object types is more accurate than using mime/types. */
 	if (CAMEL_IS_MULTIPART (containee)) {
 		parts = camel_multipart_get_number (CAMEL_MULTIPART (containee));
 		for (i = 0; i < parts && truth == FALSE; i++) {
@@ -521,11 +530,12 @@ camel_search_message_body_contains (CamelDataWrapper *object,
 				truth = camel_search_message_body_contains (part, pattern);
 		}
 	} else if (CAMEL_IS_MIME_MESSAGE (containee)) {
-		/* for messages we only look at its contents */
+		/* For messages we only look at its contents. */
 		truth = camel_search_message_body_contains ((CamelDataWrapper *) containee, pattern);
 	} else if (camel_content_type_is (CAMEL_DATA_WRAPPER (containee)->mime_type, "text", "*")
 		|| camel_content_type_is (CAMEL_DATA_WRAPPER (containee)->mime_type, "x-evolution", "evolution-rss-feed")) {
-		/* for all other text parts, we look inside, otherwise we dont care */
+		/* For all other text parts we look
+		 * inside, otherwise we don't care. */
 		CamelStream *stream;
 		GByteArray *byte_array;
 
@@ -628,8 +638,8 @@ camel_search_words_split (const guchar *in)
 	return words;
 }
 
-/* takes an existing 'words' list, and converts it to another consisting of
- * only simple words, with any punctuation etc stripped */
+/* Takes an existing 'words' list, and converts it to another consisting
+ * of only simple words, with any punctuation, etc stripped. */
 struct _camel_search_words *
 camel_search_words_simple (struct _camel_search_words *wordin)
 {
diff --git a/camel/camel-search-private.h b/camel/camel-search-private.h
index 8302ff9..04a8251 100644
--- a/camel/camel-search-private.h
+++ b/camel/camel-search-private.h
@@ -56,14 +56,27 @@ typedef enum {
 } camel_search_t;
 
 /* builds a regex that represents a string search */
-gint camel_search_build_match_regex (regex_t *pattern, camel_search_flags_t type, gint argc, struct _CamelSExpResult **argv, GError **error);
-gboolean camel_search_message_body_contains (CamelDataWrapper *object, regex_t *pattern);
-
-gboolean camel_search_header_match (const gchar *value, const gchar *match, camel_search_match_t how, camel_search_t type, const gchar *default_charset);
-gboolean camel_search_camel_header_soundex (const gchar *header, const gchar *match);
+gint		camel_search_build_match_regex	(regex_t *pattern,
+						 camel_search_flags_t type,
+						 gint argc,
+						 CamelSExpResult **argv,
+						 GError **error);
+gboolean	camel_search_message_body_contains
+						(CamelDataWrapper *object,
+						 regex_t *pattern);
+
+gboolean	camel_search_header_match	(const gchar *value,
+						 const gchar *match,
+						 camel_search_match_t how,
+						 camel_search_t type,
+						 const gchar *default_charset);
+gboolean	camel_search_camel_header_soundex
+						(const gchar *header,
+						 const gchar *match);
 
 /* TODO: replace with a real search function */
-const gchar *camel_ustrstrcase (const gchar *haystack, const gchar *needle);
+const gchar *	camel_ustrstrcase		(const gchar *haystack,
+						 const gchar *needle);
 
 /* Some crappy utility functions for handling multiple search words */
 typedef enum _camel_search_word_t {
@@ -83,9 +96,11 @@ struct _camel_search_words {
 	struct _camel_search_word **words;
 };
 
-struct _camel_search_words *camel_search_words_split (const guchar *in);
-struct _camel_search_words *camel_search_words_simple (struct _camel_search_words *wordin);
-void camel_search_words_free (struct _camel_search_words *);
+struct _camel_search_words *
+		camel_search_words_split	(const guchar *in);
+struct _camel_search_words *
+		camel_search_words_simple	(struct _camel_search_words *words);
+void		camel_search_words_free		(struct _camel_search_words *words);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]