summaryrefslogtreecommitdiffstats
path: root/source/helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/helper.c')
-rw-r--r--source/helper.c84
1 files changed, 43 insertions, 41 deletions
diff --git a/source/helper.c b/source/helper.c
index 33e94d25..1eb2b902 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -179,43 +179,44 @@ static gchar *fuzzy_to_regex ( const char * input )
return retv;
}
-static char *utf8_helper_simplify_string ( const char *s)
+static char *utf8_helper_simplify_string ( const char *s )
{
- gunichar buf2[G_UNICHAR_MAX_DECOMPOSITION_LENGTH] = {0,};
- char buf[6] = {0,};
- // Compose the string in maximally composed form.
- char * str = g_malloc0((g_utf8_strlen(s,0)*6+2));
- char *striter = str;
- for ( const char *iter = s; iter && *iter; iter = g_utf8_next_char ( iter )) {
- gunichar uc = g_utf8_get_char ( iter );
- int l = 0;
- gsize dl = g_unichar_fully_decompose ( uc, FALSE, buf2, G_UNICHAR_MAX_DECOMPOSITION_LENGTH) ;
- if ( dl ) {
- l = g_unichar_to_utf8 ( buf2[0], buf);
- } else {
- l = g_unichar_to_utf8 ( uc, buf);
- }
- memcpy(striter, buf, l);
- striter+=l;
- }
-
- return str;
+ gunichar buf2[G_UNICHAR_MAX_DECOMPOSITION_LENGTH] = { 0, };
+ char buf[6] = { 0, };
+ // Compose the string in maximally composed form.
+ char * str = g_malloc0 ( ( g_utf8_strlen ( s, 0 ) * 6 + 2 ) );
+ char *striter = str;
+ for ( const char *iter = s; iter && *iter; iter = g_utf8_next_char ( iter ) ) {
+ gunichar uc = g_utf8_get_char ( iter );
+ int l = 0;
+ gsize dl = g_unichar_fully_decompose ( uc, FALSE, buf2, G_UNICHAR_MAX_DECOMPOSITION_LENGTH );
+ if ( dl ) {
+ l = g_unichar_to_utf8 ( buf2[0], buf );
+ }
+ else {
+ l = g_unichar_to_utf8 ( uc, buf );
+ }
+ memcpy ( striter, buf, l );
+ striter += l;
+ }
+
+ return str;
}
// Macro for quickly generating regex for matching.
static inline GRegex * R ( const char *s, int case_sensitive )
{
- if ( config.normalize_match ) {
- char *str = utf8_helper_simplify_string ( s );
-
- GRegex *r = g_regex_new ( str, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL );
+ if ( config.normalize_match ) {
+ char *str = utf8_helper_simplify_string ( s );
- g_free ( str );
- return r;
- } else {
- return g_regex_new ( s, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL );
+ GRegex *r = g_regex_new ( str, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL );
- }
+ g_free ( str );
+ return r;
+ }
+ else {
+ return g_regex_new ( s, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL );
+ }
}
static rofi_int_matcher * create_regex ( const char *input, int case_sensitive )
@@ -414,7 +415,7 @@ PangoAttrList *helper_token_match_get_pango_attr ( RofiHighlightColorStyle th, r
{
// Disable highlighting for normalize match, not supported atm.
if ( config.normalize_match ) {
- return retv;
+ return retv;
}
// Do a tokenized match.
if ( tokens ) {
@@ -489,19 +490,20 @@ int helper_token_match ( rofi_int_matcher* const *tokens, const char *input )
int match = TRUE;
// Do a tokenized match.
if ( tokens ) {
- if ( config.normalize_match ) {
- char *r = utf8_helper_simplify_string(input);
- for ( int j = 0; match && tokens[j]; j++ ) {
- match = g_regex_match ( tokens[j]->regex, r, 0, NULL );
- match ^= tokens[j]->invert;
+ if ( config.normalize_match ) {
+ char *r = utf8_helper_simplify_string ( input );
+ for ( int j = 0; match && tokens[j]; j++ ) {
+ match = g_regex_match ( tokens[j]->regex, r, 0, NULL );
+ match ^= tokens[j]->invert;
+ }
+ g_free ( r );
}
- g_free(r);
- } else {
- for ( int j = 0; match && tokens[j]; j++ ) {
- match = g_regex_match ( tokens[j]->regex, input, 0, NULL );
- match ^= tokens[j]->invert;
+ else {
+ for ( int j = 0; match && tokens[j]; j++ ) {
+ match = g_regex_match ( tokens[j]->regex, input, 0, NULL );
+ match ^= tokens[j]->invert;
+ }
}
- }
}
return match;
}