Browse code

Don't require scores to be positive

Previously a successful match was determined by the score being
positive. Now we will use has_match instead.

John Hawthorn authored on 26/07/2014 09:44:12
Showing 3 changed files

  • fzy.c index 2f37ffb..c30be05 100644
  • fzy.h index 658c0cc..67f182b 100644
  • match.c index b501327..1fb9bfb 100644
... ...
@@ -77,8 +77,8 @@ void run_search(char *needle){
77 77
 	choices_available = 0;
78 78
 	int i;
79 79
 	for(i = 0; i < choices_n; i++){
80
-		choices_score[i] = match(needle, choices[i]);
81
-		if(choices_score[i] >= 0.0){
80
+		if(has_match(needle, choices[i])){
81
+			choices_score[i] = match(needle, choices[i]);
82 82
 			choices_sorted[choices_available++] = i;
83 83
 		}
84 84
 	}
... ...
@@ -1,6 +1,7 @@
1 1
 #ifndef FZY_H
2 2
 #define FZY_H FZY_H
3 3
 
4
+int has_match(const char *needle, const char *haystack);
4 5
 double match_positions(const char *needle, const char *haystack, size_t *positions);
5 6
 double match(const char *needle, const char *haystack);
6 7
 
... ...
@@ -7,7 +7,7 @@
7 7
 
8 8
 #define SCORE_MIN -1
9 9
 
10
-static int is_subset(const char *needle, const char *haystack){
10
+int has_match(const char *needle, const char *haystack){
11 11
 	while(*needle){
12 12
 		if(!*haystack)
13 13
 			return 0;
... ...
@@ -115,7 +115,7 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio
115 115
 double match_positions(const char *needle, const char *haystack, size_t *positions){
116 116
 	if(!*needle){
117 117
 		return 1.0;
118
-	}else if(!is_subset(needle, haystack)){
118
+	}else if(!has_match(needle, haystack)){
119 119
 		return SCORE_MIN;
120 120
 	}else if(!strcasecmp(needle, haystack)){
121 121
 		if(positions){