[geany/geany-plugins] f34f25: commander: Sorting: give higher score to complete word matches

Colomban Wendling git-noreply at xxxxx
Wed Sep 10 18:32:33 UTC 2014


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Wed, 10 Sep 2014 18:32:33 UTC
Commit:      f34f25ebdee051bbef25357d66b4ab05ed61dcb8
             https://github.com/geany/geany-plugins/commit/f34f25ebdee051bbef25357d66b4ab05ed61dcb8

Log Message:
-----------
commander: Sorting: give higher score to complete word matches


Modified Paths:
--------------
    commander/src/commander-plugin.c

Modified: commander/src/commander-plugin.c
13 lines changed, 7 insertions(+), 6 deletions(-)
===================================================================
@@ -114,7 +114,7 @@ enum {
 
 
 #define SEPARATORS        " -_/\\\"'"
-#define IS_SEPARATOR(c)   (strchr (SEPARATORS, (c)))
+#define IS_SEPARATOR(c)   (strchr (SEPARATORS, (c)) != NULL)
 #define next_separator(p) (strpbrk (p, SEPARATORS))
 
 /* TODO: be more tolerant regarding unmatched character in the needle.
@@ -125,13 +125,14 @@ static inline gint
 get_score (const gchar *needle,
            const gchar *haystack)
 {
-  if (needle == NULL || haystack == NULL ||
-      *needle == '\0' || *haystack == '\0') {
-    return 0;
+  if (! needle || ! haystack) {
+    return needle == NULL;
+  } else if (! *needle || ! *haystack) {
+    return *needle == 0;
   }
   
   if (IS_SEPARATOR (*haystack)) {
-    return get_score (needle, haystack + 1);
+    return get_score (needle + IS_SEPARATOR (*needle), haystack + 1);
   }
 
   if (IS_SEPARATOR (*needle)) {
@@ -139,7 +140,7 @@ get_score (const gchar *needle,
   }
 
   if (*needle == *haystack) {
-    gint a = get_score (needle + 1, haystack + 1) + 1;
+    gint a = get_score (needle + 1, haystack + 1) + 1 + IS_SEPARATOR (haystack[1]);
     gint b = get_score (needle, next_separator (haystack));
     
     return MAX (a, b);



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Plugins-Commits mailing list