From 4466ab96255e3b720a96cf6dd05cdaeef5119691 Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Wed, 24 Jul 2024 12:33:06 +0200 Subject: Add string utils --- utils/string.c | 24 ++++++++++++++++++++++++ utils/string.h | 9 +++++++++ 2 files changed, 33 insertions(+) create mode 100644 utils/string.c create mode 100644 utils/string.h (limited to 'utils') diff --git a/utils/string.c b/utils/string.c new file mode 100644 index 0000000..1975306 --- /dev/null +++ b/utils/string.c @@ -0,0 +1,24 @@ +#include +#include + +char * +ltrim(char *s) +{ + while(isspace(*s)) s++; + return s; +} + +char * +rtrim(char *s) +{ + char* back = s + strlen(s); + while(isspace(*--back)); + *(back+1) = '\0'; + return s; +} + +char * +trim(char *s) +{ + return rtrim(ltrim(s)); +} \ No newline at end of file diff --git a/utils/string.h b/utils/string.h new file mode 100644 index 0000000..a4782cb --- /dev/null +++ b/utils/string.h @@ -0,0 +1,9 @@ +#ifndef __UTILS_STRING_H__ +#define __UTILS_STRING_H__ +#include + +char *ltrim(char *); +char *rtrim(char *); +char *trim(char *); + +#endif /* __UTILS_STRING_H__ */ -- cgit v1.2.3