}
}
-static char* find_match_start(char *str, int ch) {
+static char* find_char(char *str, int ch) {
for (; *str; str++)
if (tolower(*str) == tolower(ch))
return str;
return NULL;
}
-static bool match(char *string, size_t offset, size_t *start, size_t *end) {
- char* q = Query;
- char* s = find_match_start(&string[offset], *q);
- char* e = s;
- /* bail if no match for first char */
- if (s == NULL) return 0;
+static bool find_match(char *string, char* query, size_t offset, char **start, char **end) {
+ char *s, *e;
+ /* find first match char or bail */
+ s = e = find_char(&string[offset], *query);
+ if (s == NULL) return false;
+
/* find the end of the match */
- for (q++, e++; *q; q++)
- if ((e = find_match_start(e, *q)) == NULL)
+ for (query++; *query; query++)
+ if ((e = find_char(e+1, *query)) == NULL)
return false;
- /* make note of the matching range */
+
+ /* if we made it this far, we found a match */
+ *start = s, *end = e;
+ return true;
+}
+
+static bool match(char *string, size_t offset, size_t *start, size_t *end) {
+ char *s, *e;
+ if (!find_match(string, Query, offset, &s, &e))
+ return false;
*start = s - string;
*end = e - string;
+
/* Less than or equal is used in order to obtain the left-most match. */
if (match(string, offset + 1, start, end) && (size_t)(e - s) <= *end - *start) {
*start = s - string;