1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Removed trim method from util

This commit is contained in:
James Booth 2012-04-26 23:27:40 +01:00
parent 381d4b8dc9
commit a41dab3d3c
4 changed files with 2 additions and 76 deletions

View File

@ -47,13 +47,14 @@ gboolean process_input(char *inp)
{ {
gboolean result = FALSE; gboolean result = FALSE;
g_strstrip(inp);
if (strlen(inp) > 0) if (strlen(inp) > 0)
history_append(inp); history_append(inp);
if (strlen(inp) == 0) { if (strlen(inp) == 0) {
result = TRUE; result = TRUE;
} else if (inp[0] == '/') { } else if (inp[0] == '/') {
trim(inp);
char inp_cpy[strlen(inp) + 1]; char inp_cpy[strlen(inp) + 1];
strcpy(inp_cpy, inp); strcpy(inp_cpy, inp);
char *command = strtok(inp_cpy, " "); char *command = strtok(inp_cpy, " ");

View File

@ -146,64 +146,6 @@ void replace_when_new_null(void)
assert_string_equals("hello", result); 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) void register_util_tests(void)
{ {
TEST_MODULE("util tests"); TEST_MODULE("util tests");
@ -220,10 +162,4 @@ void register_util_tests(void)
TEST(replace_when_sub_null); TEST(replace_when_sub_null);
TEST(replace_when_new_empty); TEST(replace_when_new_empty);
TEST(replace_when_new_null); 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);
} }

10
util.c
View File

@ -25,8 +25,6 @@
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <glib.h>
void get_time(char *thetime) void get_time(char *thetime)
{ {
time_t rawtime; time_t rawtime;
@ -38,14 +36,6 @@ void get_time(char *thetime)
strftime(thetime, 80, "%H:%M", timeinfo); 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, char * str_replace (const char *string, const char *substr,
const char *replacement) { const char *replacement) {
char *tok = NULL; char *tok = NULL;

1
util.h
View File

@ -24,7 +24,6 @@
#define UTIL_H #define UTIL_H
void get_time(char *thetime); void get_time(char *thetime);
char * trim(char *str);
char * str_replace(const char *string, const char *substr, char * str_replace(const char *string, const char *substr,
const char *replacement); const char *replacement);