mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Moved quote stripper to common, added tests
This commit is contained in:
parent
236e508cd8
commit
44c5b34a71
@ -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 * _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 * _sub_autocomplete(const char * const input);
|
||||||
static char * _notify_autocomplete(const char * const input);
|
static char * _notify_autocomplete(const char * const input);
|
||||||
static char * _theme_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" } ;
|
gchar *nick_choices[] = { "/msg", "/info", "/caps", "/status", "/software" } ;
|
||||||
|
|
||||||
// Remove quote character before and after names when doing autocomplete
|
// 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++) {
|
for (i = 0; i < ARRAY_SIZE(nick_choices); i++) {
|
||||||
result = autocomplete_param_with_ac(unquoted, nick_choices[i], nick_ac, TRUE);
|
result = autocomplete_param_with_ac(unquoted, nick_choices[i], nick_ac, TRUE);
|
||||||
if (result) {
|
if (result) {
|
||||||
@ -1985,7 +1983,7 @@ _cmd_complete_parameters(const char * const input)
|
|||||||
} else {
|
} else {
|
||||||
gchar *contact_choices[] = { "/msg", "/info", "/status" };
|
gchar *contact_choices[] = { "/msg", "/info", "/status" };
|
||||||
// Remove quote character before and after names when doing autocomplete
|
// 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++) {
|
for (i = 0; i < ARRAY_SIZE(contact_choices); i++) {
|
||||||
result = autocomplete_param_with_func(unquoted, contact_choices[i], roster_contact_autocomplete);
|
result = autocomplete_param_with_func(unquoted, contact_choices[i], roster_contact_autocomplete);
|
||||||
if (result) {
|
if (result) {
|
||||||
@ -3053,24 +3051,3 @@ command_docgen(void)
|
|||||||
fclose(main_fragment);
|
fclose(main_fragment);
|
||||||
g_list_free(cmds);
|
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;
|
|
||||||
}
|
|
||||||
|
22
src/common.c
22
src/common.c
@ -566,3 +566,25 @@ get_file_or_linked(char *loc, char *basedir)
|
|||||||
|
|
||||||
return true_loc;
|
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;
|
||||||
|
}
|
@ -123,5 +123,6 @@ int cmp_win_num(gconstpointer a, gconstpointer b);
|
|||||||
int get_next_available_win_num(GList *used);
|
int get_next_available_win_num(GList *used);
|
||||||
|
|
||||||
char* get_file_or_linked(char *loc, char *basedir);
|
char* get_file_or_linked(char *loc, char *basedir);
|
||||||
|
char * strip_arg_quotes(const char * const input);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -587,3 +587,47 @@ void utf8_display_len_all_wide(void **state)
|
|||||||
assert_int_equal(8, result);
|
assert_int_equal(8, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void strip_quotes_does_nothing_when_no_quoted(void **state)
|
||||||
|
{
|
||||||
|
char *input = "/cmd test string";
|
||||||
|
|
||||||
|
char *result = strip_arg_quotes(input);
|
||||||
|
|
||||||
|
assert_string_equal("/cmd test string", result);
|
||||||
|
|
||||||
|
free(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void strip_quotes_strips_first(void **state)
|
||||||
|
{
|
||||||
|
char *input = "/cmd \"test string";
|
||||||
|
|
||||||
|
char *result = strip_arg_quotes(input);
|
||||||
|
|
||||||
|
assert_string_equal("/cmd test string", result);
|
||||||
|
|
||||||
|
free(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void strip_quotes_strips_last(void **state)
|
||||||
|
{
|
||||||
|
char *input = "/cmd test string\"";
|
||||||
|
|
||||||
|
char *result = strip_arg_quotes(input);
|
||||||
|
|
||||||
|
assert_string_equal("/cmd test string", result);
|
||||||
|
|
||||||
|
free(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void strip_quotes_strips_both(void **state)
|
||||||
|
{
|
||||||
|
char *input = "/cmd \"test string\"";
|
||||||
|
|
||||||
|
char *result = strip_arg_quotes(input);
|
||||||
|
|
||||||
|
assert_string_equal("/cmd test string", result);
|
||||||
|
|
||||||
|
free(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -52,3 +52,7 @@ void utf8_display_len_1_wide(void **state);
|
|||||||
void utf8_display_len_non_wide(void **state);
|
void utf8_display_len_non_wide(void **state);
|
||||||
void utf8_display_len_wide(void **state);
|
void utf8_display_len_wide(void **state);
|
||||||
void utf8_display_len_all_wide(void **state);
|
void utf8_display_len_all_wide(void **state);
|
||||||
|
void strip_quotes_does_nothing_when_no_quoted(void **state);
|
||||||
|
void strip_quotes_strips_first(void **state);
|
||||||
|
void strip_quotes_strips_last(void **state);
|
||||||
|
void strip_quotes_strips_both(void **state);
|
||||||
|
@ -91,6 +91,10 @@ int main(int argc, char* argv[]) {
|
|||||||
unit_test(utf8_display_len_non_wide),
|
unit_test(utf8_display_len_non_wide),
|
||||||
unit_test(utf8_display_len_wide),
|
unit_test(utf8_display_len_wide),
|
||||||
unit_test(utf8_display_len_all_wide),
|
unit_test(utf8_display_len_all_wide),
|
||||||
|
unit_test(strip_quotes_does_nothing_when_no_quoted),
|
||||||
|
unit_test(strip_quotes_strips_first),
|
||||||
|
unit_test(strip_quotes_strips_last),
|
||||||
|
unit_test(strip_quotes_strips_both),
|
||||||
|
|
||||||
unit_test(clear_empty),
|
unit_test(clear_empty),
|
||||||
unit_test(reset_after_create),
|
unit_test(reset_after_create),
|
||||||
|
Loading…
Reference in New Issue
Block a user