mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-28 20:06:21 +00:00
Replaced trim implementation with g_strstrip
This commit is contained in:
@@ -53,7 +53,7 @@ gboolean process_input(char *inp)
|
|||||||
if (strlen(inp) == 0) {
|
if (strlen(inp) == 0) {
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
} else if (inp[0] == '/') {
|
} else if (inp[0] == '/') {
|
||||||
inp = trim(inp);
|
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, " ");
|
||||||
|
|||||||
@@ -199,9 +199,9 @@ void trim_when_empty(void)
|
|||||||
void trim_when_null(void)
|
void trim_when_null(void)
|
||||||
{
|
{
|
||||||
char *str = NULL;
|
char *str = NULL;
|
||||||
trim(str);
|
char *result = trim(str);
|
||||||
|
|
||||||
assert_is_null(str);
|
assert_is_null(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_util_tests(void)
|
void register_util_tests(void)
|
||||||
|
|||||||
18
util.c
18
util.c
@@ -25,6 +25,8 @@
|
|||||||
#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;
|
||||||
@@ -41,21 +43,7 @@ char *trim(char *str)
|
|||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
char *end;
|
return g_strstrip(str);
|
||||||
|
|
||||||
while (isspace(*str))
|
|
||||||
str++;
|
|
||||||
|
|
||||||
if (*str == 0)
|
|
||||||
return str;
|
|
||||||
|
|
||||||
end = str + strlen(str) - 1;
|
|
||||||
while (end > str && isspace(*end))
|
|
||||||
end--;
|
|
||||||
|
|
||||||
*(end+1) = 0;
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char * str_replace (const char *string, const char *substr,
|
char * str_replace (const char *string, const char *substr,
|
||||||
|
|||||||
Reference in New Issue
Block a user