[devhelp] KeywordModel: improve a little process_search_string()



commit f2767f5c317ac7b2cc23ab28889f54dbb4167411
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Jan 17 21:15:53 2018 +0100

    KeywordModel: improve a little process_search_string()

 src/dh-keyword-model.c |   33 ++++++++++++++++-----------------
 1 files changed, 16 insertions(+), 17 deletions(-)
---
diff --git a/src/dh-keyword-model.c b/src/dh-keyword-model.c
index 5217691..b95838c 100644
--- a/src/dh-keyword-model.c
+++ b/src/dh-keyword-model.c
@@ -743,7 +743,6 @@ process_search_string (const gchar  *string,
                        GStrv        *keywords)
 {
         gchar *processed = NULL;
-        gchar *aux;
         GStrv tokens = NULL;
         gint token_num;
         gint keyword_num;
@@ -753,19 +752,23 @@ process_search_string (const gchar  *string,
         *page_id = NULL;
         *keywords = NULL;
 
-        /* First, remove all leading and trailing whitespaces in
-         * the search string */
+        /* First, remove all leading and trailing whitespaces in the search
+         * string.
+         */
         processed = g_strdup (string);
         g_strstrip (processed);
 
-        /* Also avoid words being separated by more than one whitespace,
-         * or g_strsplit() will give us empty strings. */
-        aux = processed;
-        while ((aux = strchr (aux, ' ')) != NULL) {
-                g_strchug (++aux);
+        /* Also avoid words being separated by more than one whitespace, or
+         * g_strsplit() will give us empty strings.
+         */
+        {
+                gchar *aux = processed;
+                while ((aux = strchr (aux, ' ')) != NULL) {
+                        g_strchug (++aux);
+                }
         }
 
-        /* If after all this we get an empty string, nothing else to do */
+        /* If after all this we get an empty string, nothing else to do. */
         if (processed[0] == '\0') {
                 ret = FALSE;
                 goto out;
@@ -779,12 +782,10 @@ process_search_string (const gchar  *string,
         keyword_num = 0;
 
         for (token_num = 0; tokens[token_num] != NULL; token_num++) {
-                gchar *cur_token;
+                gchar *cur_token = tokens[token_num];
                 const gchar *prefix;
                 gint prefix_len;
 
-                cur_token = tokens[token_num];
-
                 /* Book prefix? */
                 prefix = "book:";
                 if (g_str_has_prefix (cur_token, prefix)) {
@@ -795,8 +796,7 @@ process_search_string (const gchar  *string,
                                 continue;
                         }
 
-                        /* We got a second request of book, don't allow
-                         * this. */
+                        /* We got a second request of book, don't allow this. */
                         if (*book_id != NULL) {
                                 ret = FALSE;
                                 goto out;
@@ -816,8 +816,7 @@ process_search_string (const gchar  *string,
                                 continue;
                         }
 
-                        /* We got a second request of page, don't allow
-                         * this. */
+                        /* We got a second request of page, don't allow this. */
                         if (*page_id != NULL) {
                                 ret = FALSE;
                                 goto out;
@@ -827,7 +826,7 @@ process_search_string (const gchar  *string,
                         continue;
                 }
 
-                /* Then, a new keyword to look for */
+                /* Then, a new keyword to look for. */
                 (*keywords)[keyword_num] = g_strdup (cur_token);
                 keyword_num++;
         }


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