static ShellAppInfoSearchMatch shell_app_info_match_terms (ShellAppInfo *info, GSList *terms) { GSList *iter; ShellAppInfoSearchMatch match; if (G_UNLIKELY(!info->casefolded_name)) shell_app_info_init_search_data (info); match = MATCH_NONE; for (iter = terms; iter; iter = iter->next) { ShellAppInfoSearchMatch current_match; const char *term = iter->data; const char *p; current_match = MATCH_NONE; p = strstr (info->casefolded_name, term); if (p == info->casefolded_name) current_match = MATCH_PREFIX; else if (p != NULL) current_match = MATCH_SUBSTRING; p = strstr (info->casefolded_exec, term); if (p != NULL) { if (p == info->casefolded_exec) current_match = (current_match == MATCH_NONE) ? MATCH_PREFIX : MATCH_MULTIPLE_PREFIX; else if (current_match < MATCH_PREFIX) current_match = (current_match == MATCH_NONE) ? MATCH_SUBSTRING : MATCH_MULTIPLE_SUBSTRING; } if (info->casefolded_description && current_match < MATCH_PREFIX) { /* Only do substring matches, as prefix matches are not meaningful * enough for descriptions */ p = strstr (info->casefolded_description, term); if (p != NULL) current_match = (current_match == MATCH_NONE) ? MATCH_SUBSTRING : MATCH_MULTIPLE_SUBSTRING; } if (current_match == MATCH_NONE) return current_match; if (current_match > match) match = current_match; } return match; }
static ShellAppInfoSearchMatch shell_app_info_match_terms (ShellAppInfo *info, GSList *terms) { GSList *iter; ShellAppInfoSearchMatch match; if (G_UNLIKELY(!info->casefolded_name)) shell_app_info_init_search_data (info); match = MATCH_NONE; for (iter = terms; iter; iter = iter->next) { const char *term = iter->data; const char *p; p = strstr (info->casefolded_name, term); if (p == info->casefolded_name) { if (match != MATCH_NONE) return MATCH_MULTIPLE; else match = MATCH_PREFIX; } else if (p != NULL) match = MATCH_SUBSTRING; p = strstr (info->casefolded_exec, term); if (p == info->casefolded_exec) { if (match != MATCH_NONE) return MATCH_MULTIPLE; else match = MATCH_PREFIX; } else if (p != NULL) match = MATCH_SUBSTRING; if (!info->casefolded_description) continue; p = strstr (info->casefolded_description, term); if (p != NULL) match = MATCH_SUBSTRING; } return match; }