diff options
-rw-r--r-- | command.c | 3 | ||||
-rw-r--r-- | test_util.c | 64 | ||||
-rw-r--r-- | util.c | 10 | ||||
-rw-r--r-- | util.h | 1 |
4 files changed, 2 insertions, 76 deletions
diff --git a/command.c b/command.c index ae27ac35..e0e75009 100644 --- a/command.c +++ b/command.c @@ -47,13 +47,14 @@ gboolean process_input(char *inp) { gboolean result = FALSE; + g_strstrip(inp); + if (strlen(inp) > 0) history_append(inp); if (strlen(inp) == 0) { result = TRUE; } else if (inp[0] == '/') { - trim(inp); char inp_cpy[strlen(inp) + 1]; strcpy(inp_cpy, inp); char *command = strtok(inp_cpy, " "); diff --git a/test_util.c b/test_util.c index 4888f676..ffe12506 100644 --- a/test_util.c +++ b/test_util.c @@ -146,64 +146,6 @@ void replace_when_new_null(void) assert_string_equals("hello", result); } -void trim_when_no_whitespace_returns_same(void) -{ - char *str = malloc((strlen("hi there") + 1) * sizeof(char)); - strcpy(str, "hi there"); - char *result = trim(str); - - assert_string_equals("hi there", result); - free(str); -} - -void trim_when_space_at_start(void) -{ - char *str = malloc((strlen(" hi there") + 1) * sizeof(char)); - strcpy(str, " hi there"); - char *result = trim(str); - - assert_string_equals("hi there", result); - free(str); -} - -void trim_when_space_at_end(void) -{ - char *str = malloc((strlen("hi there ") + 1) * sizeof(char)); - strcpy(str, "hi there "); - char *result = trim(str); - - assert_string_equals("hi there", result); - free(str); -} - -void trim_when_space_at_start_and_end(void) -{ - char *str = malloc((strlen(" hi there ") + 1) * sizeof(char)); - strcpy(str, " hi there "); - char *result = trim(str); - - assert_string_equals("hi there", result); - free(str); -} - -void trim_when_empty(void) -{ - char *str = malloc((strlen("") + 1) * sizeof(char)); - strcpy(str, ""); - char *result = trim(str); - - assert_string_equals("", result); - free(str); -} - -void trim_when_null(void) -{ - char *str = NULL; - char *result = trim(str); - - assert_is_null(result); -} - void register_util_tests(void) { TEST_MODULE("util tests"); @@ -220,10 +162,4 @@ void register_util_tests(void) TEST(replace_when_sub_null); TEST(replace_when_new_empty); TEST(replace_when_new_null); - TEST(trim_when_no_whitespace_returns_same); - TEST(trim_when_space_at_start); - TEST(trim_when_space_at_end); - TEST(trim_when_space_at_start_and_end); - TEST(trim_when_empty); - TEST(trim_when_null); } diff --git a/util.c b/util.c index 790c6a24..58f4fbf1 100644 --- a/util.c +++ b/util.c @@ -25,8 +25,6 @@ #include <ctype.h> #include <stdlib.h> -#include <glib.h> - void get_time(char *thetime) { time_t rawtime; @@ -38,14 +36,6 @@ void get_time(char *thetime) strftime(thetime, 80, "%H:%M", timeinfo); } -char *trim(char *str) -{ - if (str == NULL) - return NULL; - - return g_strstrip(str); -} - char * str_replace (const char *string, const char *substr, const char *replacement) { char *tok = NULL; diff --git a/util.h b/util.h index 0982f816..4326fbb4 100644 --- a/util.h +++ b/util.h @@ -24,7 +24,6 @@ #define UTIL_H void get_time(char *thetime); -char * trim(char *str); char * str_replace(const char *string, const char *substr, const char *replacement); |