diff options
author | James Booth <boothj5@gmail.com> | 2015-02-08 20:59:51 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-02-08 20:59:51 +0000 |
commit | 44c5b34a710f7c90b455ec92146530f95e25ab90 (patch) | |
tree | 4c739d224d6d67fec00c578707a062a77bf4fd19 /src | |
parent | 236e508cd88f0f22688d8d9b5d5d52d8870b04ec (diff) | |
download | profani-tty-44c5b34a710f7c90b455ec92146530f95e25ab90.tar.gz |
Moved quote stripper to common, added tests
Diffstat (limited to 'src')
-rw-r--r-- | src/command/command.c | 29 | ||||
-rw-r--r-- | src/common.c | 22 | ||||
-rw-r--r-- | src/common.h | 1 |
3 files changed, 26 insertions, 26 deletions
diff --git a/src/command/command.c b/src/command/command.c index 4a8c73e9..9f17596b 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -76,8 +76,6 @@ static gboolean _cmd_execute_alias(const char * const inp, gboolean *ran); static char * _cmd_complete_parameters(const char * const input); -static char * _strip_quotes_from_names(const char * const input); - static char * _sub_autocomplete(const char * const input); static char * _notify_autocomplete(const char * const input); static char * _theme_autocomplete(const char * const input); @@ -1970,7 +1968,7 @@ _cmd_complete_parameters(const char * const input) gchar *nick_choices[] = { "/msg", "/info", "/caps", "/status", "/software" } ; // Remove quote character before and after names when doing autocomplete - char *unquoted = _strip_quotes_from_names(input); + char *unquoted = strip_arg_quotes(input); for (i = 0; i < ARRAY_SIZE(nick_choices); i++) { result = autocomplete_param_with_ac(unquoted, nick_choices[i], nick_ac, TRUE); if (result) { @@ -1985,7 +1983,7 @@ _cmd_complete_parameters(const char * const input) } else { gchar *contact_choices[] = { "/msg", "/info", "/status" }; // Remove quote character before and after names when doing autocomplete - char *unquoted = _strip_quotes_from_names(input); + char *unquoted = strip_arg_quotes(input); for (i = 0; i < ARRAY_SIZE(contact_choices); i++) { result = autocomplete_param_with_func(unquoted, contact_choices[i], roster_contact_autocomplete); if (result) { @@ -3052,25 +3050,4 @@ command_docgen(void) fclose(toc_fragment); fclose(main_fragment); g_list_free(cmds); -} - -static char * -_strip_quotes_from_names(const char * const input) { - char *unquoted = strdup(input); - - // Remove starting quote if it exists - if(strchr(unquoted, '"') != NULL) { - if(strchr(unquoted, ' ') + 1 == strchr(unquoted, '"')) { - memmove(strchr(unquoted, '"'), strchr(unquoted, '"')+1, strchr(unquoted, '\0') - strchr(unquoted, '"')); - } - } - - // Remove ending quote if it exists - if(strchr(unquoted, '"') != NULL) { - if(strchr(unquoted, '\0') - 1 == strchr(unquoted, '"')) { - memmove(strchr(unquoted, '"'), strchr(unquoted, '"')+1, strchr(unquoted, '\0') - strchr(unquoted, '"')); - } - } - - return unquoted; -} +} \ No newline at end of file diff --git a/src/common.c b/src/common.c index 7638da31..95deecbb 100644 --- a/src/common.c +++ b/src/common.c @@ -566,3 +566,25 @@ get_file_or_linked(char *loc, char *basedir) return true_loc; } + +char * +strip_arg_quotes(const char * const input) +{ + char *unquoted = strdup(input); + + // Remove starting quote if it exists + if(strchr(unquoted, '"') != NULL) { + if(strchr(unquoted, ' ') + 1 == strchr(unquoted, '"')) { + memmove(strchr(unquoted, '"'), strchr(unquoted, '"')+1, strchr(unquoted, '\0') - strchr(unquoted, '"')); + } + } + + // Remove ending quote if it exists + if(strchr(unquoted, '"') != NULL) { + if(strchr(unquoted, '\0') - 1 == strchr(unquoted, '"')) { + memmove(strchr(unquoted, '"'), strchr(unquoted, '"')+1, strchr(unquoted, '\0') - strchr(unquoted, '"')); + } + } + + return unquoted; +} \ No newline at end of file diff --git a/src/common.h b/src/common.h index 26d4a99a..c22706ec 100644 --- a/src/common.h +++ b/src/common.h @@ -123,5 +123,6 @@ int cmp_win_num(gconstpointer a, gconstpointer b); int get_next_available_win_num(GList *used); char* get_file_or_linked(char *loc, char *basedir); +char * strip_arg_quotes(const char * const input); #endif |