summaryrefslogtreecommitdiffstats
path: root/source/helper.c
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2015-06-28 13:53:37 +0200
committerDave Davenport <qball@gmpclient.org>2015-06-28 13:53:37 +0200
commit30743d17896fc09778f615da74793013313c725f (patch)
treeeba985fa15faa08f592980c99b5a0126a94ca015 /source/helper.c
parent67089677b59b0ce67778b3f69b9e253c4f1be5fb (diff)
Move fuzzy_token_match to where it can be reused.
Diffstat (limited to 'source/helper.c')
-rw-r--r--source/helper.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/source/helper.c b/source/helper.c
index 47127866..9a5125c8 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -345,6 +345,29 @@ int token_match ( char **tokens, const char *input, int case_sensitive,
g_free ( compk );
return match;
}
+int fuzzy_token_match ( char **tokens, const char *input, int case_sensitive,
+ __attribute__( ( unused ) ) unsigned int index,
+ __attribute__( ( unused ) ) Switcher * data )
+{
+ int match = 1;
+ char *compk = token_collate_key ( input, case_sensitive );
+ // Do a tokenized match.
+ if ( tokens ) {
+ for ( int j = 0; match && tokens[j]; j++ ) {
+ char *t = compk;
+ int token_len = strlen ( tokens[j] );
+ for ( int id = 0; match && t != NULL && id < token_len; id++ ) {
+ match = ( ( t = strchr ( t, tokens[j][id] ) ) != NULL );
+ // next should match the next character.
+ if ( t != NULL ) {
+ t++;
+ }
+ }
+ }
+ }
+ g_free ( compk );
+ return match;
+}
int execute_generator ( const char * cmd )
{