summaryrefslogtreecommitdiffstats
path: root/source/helper.c
diff options
context:
space:
mode:
authorDave Davenport <DaveDavenport@users.noreply.github.com>2015-01-13 11:47:13 +0100
committerDave Davenport <DaveDavenport@users.noreply.github.com>2015-01-13 11:47:13 +0100
commit08485c0cfcc538d56e59ce4c667210db96f1f74b (patch)
tree866569d740f8c5a27a771ce16357fd408e1ab9fc /source/helper.c
parentf5688b6cc6fa95168f2a9f06db0f015908b882df (diff)
parent93a2738c8a42ab20cf4a6ecfa06bdfb01028aefe (diff)
Merge pull request #103 from EdwinPujols/master
Fix #102 - Add case sensitivity.
Diffstat (limited to 'source/helper.c')
-rw-r--r--source/helper.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/source/helper.c b/source/helper.c
index 01b3b864..5a67e2bb 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -118,7 +118,23 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... )
return FALSE;
}
-char **tokenize ( const char *input )
+char *token_collate_key ( const char *token, int case_sensitive )
+{
+ char *tmp, *compk;
+
+ if ( case_sensitive ) {
+ tmp = g_strdup ( token );
+ } else {
+ tmp = g_utf8_casefold ( token, -1 );
+ }
+
+ compk = g_utf8_collate_key ( tmp, -1 );
+ g_free ( tmp );
+
+ return compk;
+}
+
+char **tokenize ( const char *input, int case_sensitive )
{
if ( input == NULL ) {
return NULL;
@@ -137,15 +153,10 @@ char **tokenize ( const char *input )
for ( token = strtok_r ( str, " ", &saveptr );
token != NULL;
token = strtok_r ( NULL, " ", &saveptr ) ) {
- // Get case insensitive version of the string.
- char *tmp = g_utf8_casefold ( token, -1 );
-
retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) );
+ retv[num_tokens] = token_collate_key ( token, case_sensitive );
retv[num_tokens + 1] = NULL;
- // Create compare key from the case insensitive version.
- retv[num_tokens] = g_utf8_collate_key ( tmp, -1 );
num_tokens++;
- g_free ( tmp );
}
// Free str.
g_free ( str );
@@ -258,21 +269,19 @@ int find_arg_char ( const int argc, char * const argv[], const char * const key,
* Shared 'token_match' function.
* Matches tokenized.
*/
-int token_match ( char **tokens, const char *input,
+int token_match ( char **tokens, const char *input, int case_sensitive,
__attribute__( ( unused ) ) int index,
__attribute__( ( unused ) ) void *data )
{
int match = 1;
+ char *compk = token_collate_key ( input, case_sensitive );
- char *lowerc = g_utf8_casefold ( input, -1 );
- char *compk = g_utf8_collate_key ( lowerc, -1 );
// Do a tokenized match.
if ( tokens ) {
for ( int j = 0; match && tokens[j]; j++ ) {
match = ( strstr ( compk, tokens[j] ) != NULL );
}
}
- g_free ( lowerc );
g_free ( compk );
return match;
}