Browse code

Refactor into is_subset function

John Hawthorn authored on 12/07/2014 22:18:56
Showing 1 changed files

  • match.c index dc79660..abd928e 100644
... ...
@@ -1,12 +1,18 @@
1 1
 #include <ctype.h>
2 2
 
3
-double match(const char *needle, const char *haystack){
3
+static int is_subset(const char *needle, const char *haystack){
4 4
 	while(*needle){
5 5
 		if(!*haystack)
6
-			return 0.0;
7
-		while(*haystack && tolower(*needle) == tolower(*haystack++)){
6
+			return 0;
7
+		while(*haystack && tolower(*needle) == tolower(*haystack++))
8 8
 			needle++;
9
-		}
9
+	}
10
+	return 1;
11
+}
12
+
13
+double match(const char *needle, const char *haystack){
14
+	if(!is_subset(needle, haystack)){
15
+		return 0.0;
10 16
 	}
11 17
 	return 1.0;
12 18
 }