Browse code

Use SCORE_MATCH_SLASH for first character

John Hawthorn authored on 04/08/2014 02:17:32
Showing 2 changed files

... ...
@@ -44,6 +44,9 @@ int test_scoring(){
44 44
 	/* Prefer shorter matches */
45 45
 	assert(match("test", "tests") > match("test", "testing"));
46 46
 
47
+	/* Scores first letter highly */
48
+	assert(match("test", "testing") > match("test", "/testing"));
49
+
47 50
 	/* Prefer shorter matches */
48 51
 	assert(match("abc", "    a b c ") > match("abc", " a  b  c "));
49 52
 	assert(match("abc", " a b c    ") > match("abc", " a  b  c "));
... ...
@@ -81,7 +81,7 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio
81 81
 
82 82
 		score_t score = 0;
83 83
 		if(isalnum(ch)){
84
-			if(last_ch == '/'){
84
+			if(!last_ch || last_ch == '/'){
85 85
 				score = SCORE_MATCH_SLASH;
86 86
 			}else if(last_ch == '-' ||
87 87
 					last_ch == '_' ||