diff options
author | unisgn <unisgn@users.noreply.github.com> | 2021-05-29 19:39:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-29 13:39:31 +0200 |
commit | c3e70d4e1abd3d0b75a6c0dfeca56179b18b77cf (patch) | |
tree | d244465ce8d0e932aa42613cfafb88a16c82f9d4 /source | |
parent | 24dde5801930342a177457ad862b375884630840 (diff) |
add prefix matching method feature (#1237)
* add prefix matching method feature
* Update helper.c
* prefix matching regex memory leak fix
* prefix matching regex memory leak fix
Co-authored-by: francis <oxfrancis@outlook.com>
Diffstat (limited to 'source')
-rw-r--r-- | source/helper.c | 18 | ||||
-rw-r--r-- | source/xrmoptions.c | 2 |
2 files changed, 18 insertions, 2 deletions
diff --git a/source/helper.c b/source/helper.c index 6061e064..874ceea2 100644 --- a/source/helper.c +++ b/source/helper.c @@ -179,6 +179,14 @@ static gchar *fuzzy_to_regex ( const char * input ) return retv; } +static gchar *prefix_regex (const char * input) +{ + gchar *r = g_regex_escape_string(input, -1); + char *retv = g_strconcat("\\b", r, NULL); + g_free(r); + return retv; +} + static char *utf8_helper_simplify_string ( const char *s ) { gunichar buf2[G_UNICHAR_MAX_DECOMPOSITION_LENGTH] = { 0, }; @@ -248,6 +256,11 @@ static rofi_int_matcher * create_regex ( const char *input, int case_sensitive ) retv = R ( r, case_sensitive ); g_free ( r ); break; + case MM_PREFIX: + r = prefix_regex(input); + retv = R(r, case_sensitive); + g_free(r); + break; default: r = g_regex_escape_string ( input, -1 ); retv = R ( r, case_sensitive ); @@ -632,8 +645,11 @@ int config_sanity_check ( void ) else if ( g_strcmp0 ( config.matching, "normal" ) == 0 ) { config.matching_method = MM_NORMAL;; } + else if (g_strcmp0 (config.matching, "prefix") == 0) { + config.matching_method = MM_PREFIX; + } else { - g_string_append_printf ( msg, "\t<b>config.matching</b>=%s is not a valid matching strategy.\nValid options are: glob, regex, fuzzy or normal.\n", + g_string_append_printf ( msg, "\t<b>config.matching</b>=%s is not a valid matching strategy.\nValid options are: glob, regex, fuzzy, prefix or normal.\n", config.matching ); found_error = 1; } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 344f3b89..b597decc 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -169,7 +169,7 @@ static XrmOption xrmOptions[] = { { xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL, "Set the modi to combine in combi mode", CONFIG_DEFAULT }, { xrm_String, "matching", { .str = &config.matching }, NULL, - "Set the matching algorithm. (normal, regex, glob, fuzzy)", CONFIG_DEFAULT }, + "Set the matching algorithm. (normal, regex, glob, fuzzy, prefix)", CONFIG_DEFAULT }, { xrm_Boolean, "tokenize", { .num = &config.tokenize }, NULL, "Tokenize input string", CONFIG_DEFAULT }, { xrm_String, "monitor", { .str = &config.monitor }, NULL, |