diff options
author | 2024-07-24 12:33:06 +0200 | |
---|---|---|
committer | 2024-07-24 12:33:06 +0200 | |
commit | 4466ab96255e3b720a96cf6dd05cdaeef5119691 (patch) | |
tree | 354dc0290ae883fa147afda8e6ec4b9700d345ad | |
parent | d3f087278b3ed9e520c92947292c7e55df09f4d1 (diff) | |
download | properties-4466ab96255e3b720a96cf6dd05cdaeef5119691.tar.gz properties-4466ab96255e3b720a96cf6dd05cdaeef5119691.zip |
Add string utils
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | utils/string.c | 24 | ||||
-rw-r--r-- | utils/string.h | 9 |
3 files changed, 37 insertions, 1 deletions
@@ -3,7 +3,7 @@ LEX = lex YACC = yacc CC = cc -OBJ = properties-parser.o properties-lexer.o +OBJ = utils/string.o properties-parser.o properties-lexer.o CFLAGS = -DVERSION=${VER} LFLAGS = -ll -ly @@ -23,6 +23,9 @@ properties-parser.o properties-parser.h: properties.y @mv y.tab.h properties-parser.h ${CC} ${CFLAGS} -c properties-parser.c +utils/string.o: utils/string.c + ${CC} ${CFLAGS} -c $< -o $@ + properties: ${OBJ} ${CC} ${OBJ} -o $@ ${LFLAGS} 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 <ctype.h> +#include <string.h> + +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 <string.h> + +char *ltrim(char *); +char *rtrim(char *); +char *trim(char *); + +#endif /* __UTILS_STRING_H__ */ |